The document presents a simple C program for determining whether a number is prime. It utilizes a for loop and if-else statements to check divisibility. Sample outputs demonstrate the program's functionality with input numbers 30 and 53.
2. Sitesbay.com
Prime Number Program in C
This is very simple and easy to write Prime Number Program in C. You need for loop and
if..else statements.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,t=0,flag=0;
clrscr();
printf("Enter any Number:");
scanf("%d",&num);
t=num/2;
for(i=2; i<=t; i++)
{
if(num%i==0)
{
printf("Number is not prime");
flag=1;
break;
}
}
if(flag==0)
printf("Number is prime");
getch();
}