Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Check , given number is PRIME or not .....



Program use to find the input number is prime or not. Simple logic is applied  if(num%i==0) with the help of count variable ,we identify the prime number.




Source Code:-

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
   int num, i,count=0;
   cout<<"Program to check no. is Prime (by: Tarun Rawat)\n\n";
   cout<<"Enter number to check Prime or not :- ";
   cin>>num;
   for(i=2;i<=num;i++)
     { if(num%i==0)
 count=count+1;
     }
     if(count==1)
       cout<<"\n"<<num<<" is a Prime number";
     else cout<<"\n"<<num<<" is not a prime number";
getch();
}



No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)