Monday, February 8, 2016

C++ Program to Check Whether a give number is Prime or Not

//Program to check whether the given number is Prime or Not.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int N,flag=0;
cout<<"\nEnter number to check whether it is prime or not:";
cin>>N;
for(int i=2;i<N;i++)
{
if(N%i==0)
flag=1;
}
if(flag==1)
cout<<"\nIt is not a prime number!";
else if(flag==0)
cout<<"\nThe given number is a prime number!";
getch();
}

No comments:

Post a Comment

Pages