Program to Check Whether a Number is Prime or Not


 Prime Number Program


In this article, we discussed the program to check whether a number is Prime or not.


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


#include<iostream>
using namespace std;
int main()
{
    int n;
    cout<<" Enter the Number "<<endl;
    cin>>n;
    bool isPrime=1;
    for(int i=2;i<n; i++){
        if(n%i==0){
            //cout<<"Not Prime"<<endl;
            isPrime=0;
            break;            // Use of Break
        }
       
    }
    if(isPrime==0){
        cout<<"Not a Prime number"<<endl;

    }
    else
    {
        cout<<"Prime Number"<<endl;
    }
}


if ( This Post was Helpful )

{   

      <<"Do Share it with Your Friends and Classmates">>

}

return Comments and Likes;