Program to check whether given number is prime or not

#include<iostream.h>
#include<conio.h>
void main()
{
    int i,num;
    clrscr();
    cout<<"\nEnter a number : ";
    cin>>num;
    i=2;
    while(i<=num-1)
    {
        if(num%i==0)
        {
            cout<<"\nNot a prime no.";
            break;
        }
        i++;
    }
    if(i==num)
        cout<<"\nPrime number";
    getch();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|