Saturday, December 31, 2011

Find whether natural number is prime or not. in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,count=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
i=1;
while(i<=n)
{
if(n%i==0)
{
count++;
}
i=i+1;
}
if(count<=2)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
getch();
}
/*======================================================================
OUTPUT
Enter the number:5
It is a prime number
*/

No comments:

Post a Comment