To select prime number from array
Code:
// display prime number from array
#include<stdio.h>
int main()
{
int arr[20];
int n,i,j;
printf("\n Enter the values in array ");
for(i=0;i<=10;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<=10;i++)
{
printf("%d",arr[i]);
}
printf("\n PRIME NUMBERS IN ARRAY ARE :---");
for(i=0;i<=10;i++)
{
int flag = 0;
for(j=2;j<arr[i];j++)
{
if(arr[i]%j == 0)
{
flag = 1;
//printf("\n %d / %d",arr[i],j);
break;
}
}
if(flag == 0)
{
printf(" %d",arr[i]);
}
}
}
}
No comments :
Post a Comment