/* Program to Check if number is prime or not */
#include<iostream>
#include<conio.h> //conio is used for getch
int main()
{
using namespace std;
int no,flag=0;
cout<<"Enter the natural number\t";
cin>>no;
for(int i = 2; i < no/i; i++) // prime number start with 2
{
if(no%i==0) //if prime number not exist
{
flag = 1;
break;
}
else // if prime number exist
flag = 0;
}
if(flag == 1)
cout<<no<<" is non prime number.";
else
cout<<no<<" is prime number.";
getch();
return 0;
}
#include<iostream>
#include<conio.h> //conio is used for getch
int main()
{
using namespace std;
int no,flag=0;
cout<<"Enter the natural number\t";
cin>>no;
for(int i = 2; i < no/i; i++) // prime number start with 2
{
if(no%i==0) //if prime number not exist
{
flag = 1;
break;
}
else // if prime number exist
flag = 0;
}
if(flag == 1)
cout<<no<<" is non prime number.";
else
cout<<no<<" is prime number.";
getch();
return 0;
}
0 Comments:
Post a Comment