Wednesday, 16 November 2016

Write a C++ program to input intergers and only display Prime numbers in array.


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;
               }

          

1 comment:

  1. 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

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...