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
*/
#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