prime number or not in cpp

technical talkiess
0

 // Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;

int main() {

  int num;

  bool prime_number = 1;

  cout<<"Enter the number ";

  cin>>num;

  for(int i =2;i<num;i++){

    //   if modules is 0 then not a prime 

    if(num%i==0){

        prime_number = 0;

        break;

    }

  }

  if(prime_number == 0){

      cout << "Not a prime number ";

  }else{

      cout<<"Is the Prime number";

  }


    return 0;

}

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)