Program in the C programming language to find all the prime numbers from the inputted array. Below is the C program –

/* C program to find all prime numbers from the inputted array */ #include<stdio.h> #include<conio.h> void main() { int ar[100],i,n,j,counter; printf("Enter the size of the array "); scanf("%d",&n); printf("\n Now enter the elements of the array"); for(i=0;i<n;i++) { scanf("%d",&ar[i]); } printf(" Array is -"); for(i=0;i<n;i++) { printf("\t %d",ar[i]); } printf("\n All the prime numbers in the array are -"); for(i=0;i<n;i++) { counter=0; for(j=2;j<ar[i];j++) { if(ar[i]%j==0) { counter=1; break; } } if(counter==0) { printf("\t %d",ar[i]); } } getch(); }

Output –

Enter the size of the array – 5

Now enter the elements of the array – 23 98 45 101 6

Array is – 23 98 45 101 6

All the prime numbers in the array are – 23 101

Thank you..,

nice artical ..fanx

thank you

Can you please rewrite this for Java using Jcreator?

Thank u v. Much

thank you so much

in the final “IF”, why should be “==0” instead of “=0”?

anybody?:)

because single ‘=’ means assigning a value and ‘==’ is to mean equal

Is 1 prime?

why value of ‘y’ is from 2 ,not 1

thanks a lot as i have the got the output……..

thanking you,

hunterman….