Sunday, July 21, 2013

Program to check whether a given number is prime or not using "for loop"

#include<iostream.h>
#include<process.h>
void main()
{
int num,i;
clrscr();
cout<<"Enter the number ";
cin>>num;
for(i=2;i<=num/2;++i)
if(num%i==0)
{
    cout<<"Not a prime number ";
    exit(0);
}
cout<<"It is prime number ";
getch();
}

No comments:

Post a Comment