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