I am trying to loop through an array and count the number of prime numbers in it…Simple enough but I am missing something…
count = 0;
for(i =0; i<5; i++)
{
flag = true; // is prime
for (j=2;j<a[i];j++)
{
if(a[i] % j == 0)
{
flag = false;
}
}
count ++;
}
Change your code to this
Once you have counted a non prime you might as well break out of the loop – it is not going to become unprime again with repeated testing