Write a program that inputs ten integers in an array and counts all prime numbers entered by the user. The program finally displays total number of primes in array.
Solution:
#include <iostream.h>
#include <conio.h>
int main ()
{
clrscr();
int array[10], i, c, p;
int count = 0;
cout << "Enter 10 integer numbers: ";
for(i = 0; i < 10; i++)
{
p = 1;
for(c = 2; c < array[i] / 2; c++)
{
if( arr[i] % c == 0)
{
p = 0;
break;
}
if(p == 1)
count++;
}
cout << " Total number of prime numbers in the array is : " << count;
return 0;
}
This code is frequently ask in any examination Prime number program in C++ is very simple and easy to write. Using for loop and if else we can write this code. Your code is very simple and easy to understand. Thanks for sharing this article.
ReplyDelete