HomeC++

How To Check Whether a Number is Prime or Not using C++

How To Check Whether a Number is Prime or Not using C++
Like Tweet Pin it Share Share Email

Today we make a Simple Program how to find the prime number using c++.

What is a PRIME NUMBER?
” A Natural number greater than 1 which has only two divisor 1 and itself is called prime number “.

Example to check whether an integer (entered by the user) is a prime number or not using for loop and if…else statement.

Also don’t miss some of the other Program: 

#How To Find Larger Number list of Numbers Entered By user Using C++

#How To Calculate The Average of all the values in the Array C++ Program

#How To Fill The Array of Five Elements in C++ Program

#How To Fill and Display Array Using Functions C++

#How To Display Data Type of int, float, double and char Size using C++ Program

C++ Program to Check Whether a Number is Prime or Not

#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int x;
for(int i=1;i<=100;i++){
cout<<"Enter the number"<<endl;
cin>>x;
if(x==2 || x==3 || x==5){
cout<<"Number is prime"<<endl;
}
else if(x%2==0 || x%3==0 || x%5==0)
{
cout<<"Not prime"<<endl;
}
else
{
cout<<"Number is prime"<<endl;
}

}
getch();
}

#How To Calculate The Average Maximum and Minimum Temperature of 7 Days using Array in C++
Output of Program
C++ Program to Check Whether a Number is Prime or Not

Read More Programs:-

#How To Calculate The Sum of All Values in An Array C++ Program

#How To Make Multiplication Table Of a Given Number Using while Loop in C++ Program

#How To Find the Factorial of a Number using while loop in C++ Program

#How To Convert Miles into kilometer using in C++ Program

#How To Make A Biodata Using in C++ Program

Comments (0)

Leave a Reply

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