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



void main()


int n,i=2;


printf("Enter a number \n");




if(n % i == 0)


printf("Not a Prime Number");






printf("Prime Number");





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.


More by this Author

Comments 8 comments

pooja0908 profile image

pooja0908 6 years ago from Delhi

very initial hub for c programming

i think it will help newbie of c programming

profile image

gaig 6 years ago Author

thanks a lot

ShallyD profile image

ShallyD 6 years ago from USA

thanks for this program.

do write the output of this program

profile image

gaig 6 years ago Author

OUTPUT: If we enter 9, the result will be "Not Prime"

If we enter 11, the result will be "Prime"

RENU 6 years ago

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

jitendra chavan 4 years ago

i can understand

irfan 3 years ago

good for understanding because of in simple language

gurdiv singh 3 years ago

Thnkxxx alot

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    Click to Rate This Article