Ive wrote a C program to find out whether a number is prime. But it doesnt work on some numbers, eg 25(adsbygoogle = window.adsbygoogle || []).push({});

Any help, ideas are most welcome

#include<stdio.h>

#include<math.h>

int main()

{

int j,number;

scanf("%d",&number);

if(number<=1)

return 0;

else if(number==2)

return 1;

else

for(j=3;j<(int)sqrt(number);j+=2)

{

if(number%j==0)

printf("not prime\n");

else

printf("prime\n");

return 1;

}

return 0;

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C program-prime

**Physics Forums | Science Articles, Homework Help, Discussion**