I'm working on this program that should output 10 prime numbers. So my problem is that I dont know how to tell the program to stop as soon as 10 prime numbers have been stored in the array. I tried to do sizeof(primes)/siseof(int) == 10 , but its not working. Help me please. Thanks in advance
int ar[100],primes[10],j,n,i,var;
printf("Enter a prime ,\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
if (IsPrime(ar[i])) {
primes[i] = ar[i];
if( sizeof(primes) / sizeof(int) == 10) break;
} else {
printf("%d is not a prime number\n", ar[i]);
}
}
printf("\narray :\n");
sizeof(primes) / sizeof(int)is the size of the wholeprimesarray, not the number that you've filled in so far.primes[i] = ar[i];Clearly that's not right. Consider ifiis 80. Also,sizeofis the size of the container, not its contents. It doesn't change when the contents change. So checkingsizeofis wrong too.ar[]at the end, not the contents ofprimes[]?