- #1
Dili
- 13
- 0
Ive wrote a C program to find out whether a number is prime. But it doesn't work on some numbers, eg 25
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;
}
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;
}