Advance Programs On For LoopLearn C ProgrammingLearn ProgrammingLoop Control StructuresResources

048. Write a program to accept a number from user and print if it is prime or not in C language

By September 18, 2012 February 5th, 2018 4 Comments
#include<conio.h>  
#include<process.h>
main()
{
	int i,n;
	clrscr();
	printf("Enter number...");
	scanf("%d",&n);
	for(i=2;i<=n/2;i++)
	{
		if(n%i==0)
		{
		printf("Not Prime");
		getch();
		exit(0);
		}
	}
	printf("Prime ");
	getch();
}


4 Comments

Leave a Reply

DEMO01