plz send me the source code for finding whether a no. is prime or not
plz send me the source code for finding whether a no. is prime or not
int n,x,r;
scanf("%d",&n);
for (x=2;x<=n/2;x++)
{ r = n % x;
if ( r!=0) break;
}
if ( r==0) printf("Prime");
else printf("Not prime");
Regards,
Anoop :)
If its useful, dont forget to [COLOR="Red"]THANK[/COLOR] me :cool:
Hi haltalk,
I think the last 2 lines
"if ( r==0) printf("Prime");
else printf("Not prime");"
should be like this:
"if ( r==0) printf(" not Prime");
else printf(" prime");"
Hi varun,
I think you are studying in college. Try to use google search....You can get so much of results for these type of requirements...
---------------------
suresh
Hi Rpgubba, you are right. Anyway,sorry for the mistake, and the last lines should be like this as pointed out by rpgubba!
"if ( r==0) printf(" not Prime");
else printf(" prime");"
Regards,
Anoop :)
If its useful, dont forget to [COLOR="Red"]THANK[/COLOR] me :cool: