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:-
0 Comments