# Check weather a given no is Prime or Not using c programming

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i=2;

clrscr();

printf("Enter a number \n");

scanf("%d",&n);

while(i<=n/2)

{

if(n % i == 0)

{

printf("Not a Prime Number");

getch();

exit(0);

}

i=i+1;

}

printf("Prime Number");

getch();

exit(0);

}

----------------------------------------------------

NB: n % i == 0 -------> here the we get the remainder when n is divided by each i, at any time the remainder is 0, the program will terminate and show a message " not prime". otherwise it will execute till i reaches to n/2. and terminate the program and shows a message "prime".

thanking you.

hope u understand the logic. ur comments are valuable.

-----------------------------------------------------------

## Comments 8 comments

very initial hub for c programming

i think it will help newbie of c programming

thanks for this program.

do write the output of this program

I am struggle with prime or not programme very very thanks to given this programme

i can understand

good for understanding because of in simple language

Thnkxxx alot

8