C++ Examples
C++ ExamplesPrograms with output

C++ Program to Check Number is Prime or Not


Example:
#include<iostream>
using namespace std;

int main()
{
    int num, i, temp=0;
    cout << "Enter any Number: ";
    cin >> num;
    
    for(i=2; i<num; i++)
    {
        if(num%i==0)
        {
            temp++;
            break;
        }
    }
    
    if(temp==0)
        cout << "\nIt is Prime Number";
    else
        cout << "\nIt is not Prime Number";
    cout<<endl;
    return 0;
}
Output:
Enter any Number:
15
It is not Prime Number

Share this page on:

Was this page helpful ?

Let us know how we did!

Subscribe Email Updates

to get latest update