Prime number in C.

Program to find prime number in C.

Prime number : A prime number is a number whose only factors are 1 and itself. That means there is no whole number that evenly divides the prime number.

Let’s write a program to find prime number in C.

Step 1: Let’s open turbo c and write the following code:

//Add preprocessor file

#include
#include

void main()
{

//declare variable
long int i,n,c=0;

//clear screen
clrscr();

printf(“enter any number : ”);

//Assign value in variable n
scanf(“%li”,&n);
for(i=1;i<=n;i++)
{
if (n%i==0)
{
c++;
}
}
if(c==2)
{
printf(“this is prime number”);
}
else
{
printf(“this is not a prime number “);
getch();
}

Step 2: Now save it by pressing F2 and name it prime.cpp.

Step 3: After save it ,Compile it by pressing ALT+F9 to check errors and correct them.

prime compile

Step 4: Now run the program by click on Run or by pressing ALT+R and see the output .

Output :