A place for coders and developers to share, learn and grow together.
C++ | Finding prime numbers from array
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.
//clear the screen.
//declare variable type int
//Input the two numbers save them in arrays.
//Here for loop is used to input multiple numbers in array.
cout<<"Enter the no."<<endl;
//Draw a line for good looking program.
cout<<"Prime numbers are "<<endl;
//Print the array.
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 1. You enter the number. 2. The number is saved in respective array. 3. The numbers from arrays are taken and tested if prime number. 4. The prime numbers are printed.
Explanation. 1. Include ‘iostream.h’ and ‘conio.h’ files. 2. Add void main. 3. Start program by first clearing the screen. 4. Declare the variables as int (name them as you want.) 5. Add the cout and cin of array. 6. Add for loop to find prime number. 7. Print the prime number.
At the end You learnt creating the C++ program of Finding prime numbers from array. So now enjoy the program.
P.S. If you have any questions, click here to join our community and feel free to ask any questions.