I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int num, i, f;
//Reading a number from user
cout<<"Enter any number:";
cin>>num;
f = 0;
i = 2;
while(i <= num/2)
{
if(num%i == 0)
{
f=1;
break;
}
i++;
}
if(f == 0)
cout<<num<<" is a Prime Number"<<endl;
else
cout<<num<<" is Not a Prime Number"<<endl;
return 0;
}
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
Result:
Enter any number:19
19 is a Prime Number
need an explanation for this answer? contact us directly to get an explanation for this answer