Prime or not in C++

Number which are only divided by 1 or itself is said to be a Prime Number

Source code :


#include <iostream>

using namespace std;

int main()
{
    int i,r=0,s=0;
    
    int n = 5; //Change your Number here
    
    for(i=2;i<n;i++)
    {
        s=n%i;
        
        if(s==0){
            r=1;
            break;
        }
    }
    
    if(r==0){
        cout<<n<<" is prime number";
    }
    else{
        cout<<n<<" is not prime number";
    }

    return 0;
}

Output :

5 is prime number

Output :


                

Comments :