277,853 views
34 votes
34 votes
write a program that input ten integers in an array and counts all prime numbers entered by the user. the program finally display total number of primes in array.

User Wonderer
by
3.1k points

1 Answer

17 votes
17 votes

Answer:

int main ()

{

int arr[10], i, p=0, c, prime=0;

for(i=0;i<10;i++)

{

cout<<"Enter an integer:";

cin>>arr[i];

}

cout<<"The prime numbers are:\\";

for(i=0;i<10;i++)

{

if(arr[i]>1)

{

p=1;

for(c=2;c<arr[i];c++)

{

if(arr[i]%c==0)

{

p=0;

break;

}

}

}

if(p==1)

{

cout<<arr[i]<<" is a prime number.\\";

prime++;

}

}

cout<<"total prime numbers entered by the user are: "<<prime;

}

Step-by-step explanation:

this should be good

User Diego Lope Loyola
by
3.1k points