Join Programming and Development Chat Groups on Uphub.io

**Introduction**

This is program to find the prime numbers form the array list. The program is given below. The program is not extendable. Go enjoy the program. Lets begin…….

**Program to find prime number from array list.**

```
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a[10],i,j,f,m;
//Input the two numbers save them in arrays.
//Here for loop is used to input multiple numbers in array.
for(i=0;i<5;i++)
{
cout<<"Enter the no."<<endl;
cin>>a[i];
}
//Draw a line for good looking program.
cout<<"------------------------------------"<<endl;
cout<<"Prime numbers are "<<endl;
//Print the array.
for(i=0;i<5;i++)
{
f=0;
for(j=2;j<a[i];j++)
{
m=a[i]%j;
if(m==0)
{
f=1;
break;
}
}
if(f==0)
cout<<a[i]<<endl;
}
//get character
getch();
}
```

**Output**

Enter the number

2

Enter the number

3

Enter the number

4

Enter the number

5

Enter the number

6

————————————

Prime numbers are

2

3

5

**How does it work**

- You enter the number.
- The number is saved in respective array.
- The numbers from arrays are taken and tested if prime number.
- The prime numbers are printed.

**Extending it**

The program cannot be extended.

**Explanation.**

- Include ‘iostream.h’ and ‘conio.h’ files.
- Add void main.
- Start program by first clearing the screen.
- Declare the variables as int (name them as you want.)
- Add the cout and cin of array.
- Add for loop to find prime number.
- Print the prime number.

**At the end**

You learnt creating the C++ program of Finding prime numbers from array. So now enjoy the program.

Please comment on the post and share it.

And like it if you liked.