loader image

C program to check prime number

Aim: Check whether a number is prime or not using C.

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,n,prime=1;
	clrscr();
	printf("Enter a number : ");
	scanf("%d",&n);
	for(i=2;i<=n/2;i++)
	if(n%i==0)
	{
		prime=0;
		break;
	}
	if(prime)
            printf("\n%d is prime",n);
	else
            printf("\n%d is not prime",n);
}
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top