Sunday, March 16, 2014

Prime Number

With the help of this program, you can easily find out whether a given number is prime of not. In this program, we divide the given number from 1 to that number and check the remainder. If it (remainder) becomes zero at any point before reaching that number, the program declares the number as "not prime". Otherwise, if remainder becomes zero at the given number, then the number will be prime. Here 'count' is used as a checker.                                                                                                                                                


void main ()


int n,count=1,rem=1;

cout<<"Enter the number:  ";

 cin>>n;               //entering the number

while (rem!=0)


 count++;                //dividing the given the number with each number (from 1 to that num) to chech remainder



if (count<n)

 cout<<endl<<"Given number is not prime";

  else if (count==n)         //output

 cout<<endl<<"Given number is prime";

getch ();




Copyright @ 2014 CPP Fuzz.