Prime Number Program In C

C PROGRAM TO ENTER A NUMBER BY USER AND TO CHECK WHETHER IT IS A PRIME NUMBER OR NOT.

A prime number is a number that is divisible by itself and 1 is called a prime number.

#include<stdio.h>
#include<conio.h>

void main ()
{
int n,i,x=0;
clrscr();
printf(“enter any number”);
scanf(“%d”,&n);

for(i=2;i<n;i++)
{
if(n%i==0)
{
x++;
}
}
if(x==0)
{
printf(“prime”);
}
else
{
printf(“not prime”);
}
getch();
}

Output:

prime number program in C

prime number program in c

Leave a Reply