adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

program in c++ to check a given number is prime or not using bool keyword

Program in C++ to check a given number is prime or not using bool keyword 


#include<iostream>
#include<conio.h>
 using namespace std;
  bool Prime(int n)
  {
        int i;
        bool p=true;
        for(i=2;i<=n/2;i++)
        if(n%i==0)  //if(n%i==false)
         {
            p=false;
            break;
         }
        return p;
  }
  void main()
  {
       cout<<"Enter a number:-";
       int x;
       cin>>x;
       bool b1=Prime(x);
       if(b1==true)
        cout<<x<<" is prime no.";
      else
        cout<<x<<" is not prime no.";
    getch();
  }
Output:-









Post a Comment

0 Comments