Prime Number Program in C++

  1. #include <iostream.h>  
  2. #include <conio.h> 
  3. void main()  
  4. {  
  5. clrscr();
  6.   int n, i, m=0, flag=0;  
  7.   cout << "Enter the Number to check Prime: ";  
  8.   cin >> n;  
  9.   m=n/2;  
  10.   for(i = 2; i <= m; i++)  
  11.   {  
  12.       if(n % i == 0)  
  13.       {  
  14.           cout<<"Number is not Prime."<<endl;  
  15.           flag=1;  
  16.           break;  
  17.       }  
  18.   }  
  19.   if (flag==0)  
  20.       cout << "Number is Prime."<<endl;  
  21.   getch();
  22. }  

Popular posts from this blog

kerala state rutronix fundamentals & operating system malayalam notes with previous Q&A