Saturday, 28 May 2016

Q: 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.

Program:

#include<iostream.h>
#include<conio.h>
void main()
{
   int array[10], i,c,p;
   int count=0;
   clrscr();
   cout<<"Enter integer numbers:";
   for(i=0; i<10; i++)
   {
      p=1;
     for(c=2; c<array[i]/2; c++)
     {
         if(array[i]%c==0)
         p=0;
         break;
      }
    if(p==1)
    count++;
   }
    cout<<"Total number of prime numbers in the array is: "<<count;
    getche();
}

No comments:

Post a Comment