Program to check whether the given number is prime or not
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
int rem=0;
int x=0;
int i;
clrscr();
printf("Enter number: ");
scanf("%d",&n);
if(n==1 || n==2)
{
x=1;
}
else
{
for(i=2;i<n;i++)
{
rem=n%i;
if(rem==0)
{
x=0;
break;
}
else
{
x=1;
}
}
}
if(x==1)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
getch();
}
Output :
0 comments:
Post a Comment