Program to check whether a given number is prime number - 100 Most Important C# Programs

100 Most Important C# Programs

53. Program to check whether a given number is prime number.

Code:

# include <stdio.h>

# include <conio.h>

main( )

{

int i,n,c=0;

clrscr( );

printf(“enter a number”);

scanf(“%d”,&n);

for(i=0;i<=n;i++)

if(n%i==0)

c++;

if(c==2)

printf(“given number is a prime number”);

else

printf(“given number is not prime

number”);

getch( );

}