C++ program to find prime numbers in entered array

Program to find prime numbers in array

C++ program to find prime numbers in entered array.Prime numbers are those which are divisible only by itself and 1.

Program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int j,i,x[100],y,count;
cout<<"Enter size of array:- ";
cin>>y;
cout<<"Enter elements in array:- "<<endl;
for(i=1;i<=y;i++)
{
 cin>>x[i];
}
cout<<"Prime numbers are:- "<<endl;
  for(i=1;i<=y;i++)
{       count=0;
      for(j=2;j<=x[i]/2;j++)
      {
	   if(x[i]%j==0)
	   {
	   count++;
	   break;
	   }
      }

      if(count==0)
      {

       cout<<x[i]<<endl;
      }


}
getch();
}

Output

 find Prime numbers in entered array


Comment below if you are facing any problem.


Also read

C++ program to Enter Elements in array of your choice
C++ Program to find the Largest element in the array
C++ program to Sort the Entered Element in array
C++ program to Insert an element Into sorted array
C++ program to print alternate elements from an array
C++ program to multiply two entered matrix


Summary
C++ program to find prime numbers in entered array
Article Name
C++ program to find prime numbers in entered array
Description
The program illustrate the concept to find prime numbers in entered array.Prime numbers are those which are divisible only by itself and 1.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *