To check a given number is prime or not using C


Levels of difficulty: / perform operation:

C program to check a given number is prime or not.

C Program

#include <stdio.h>
#include <conio.h>
void main()
{
	int n,i,c=0;
	clrscr();
	printf("\nENTER A NUMBER: ");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		if(n%i==0)
			c++;
	}
	if(c==2)
		printf("\n%d IS A PRIME NUMBER",n);
	else
		printf("\n%d IS NOT A PRIME NUMBER",n);
	getch();
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview