C++ Program to Check Prime or Not


-

-

Example:

Copied
#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