ok i got rid of the ";" after the "x++" and i've added another ")" to finish off the if statement, but now i'm getting this error:
Code:
/tmp/ccoKCW7q.o: In function `prime':
/tmp/ccoKCW7q.o(.text+0x81): undefined reference to `sqrt'
collect2: ld returned 1 exit status
whats wrong with it now?
here's the code:
Code:
#include <stdio.h>
#include <math.h>
int prime( int ); /* function prototype */
int main()
{
int x;
for(x=1; x<=10000; x++)
{
if( prime( x ) == 1);
{
printf( "%d\n", x );
}
}
}
int prime( int n )
{
int a_prime;
int i;
float high;
a_prime = 1;
if ((n%2)==0)
{
a_prime = 0;
}
high = sqrt((float) n);
for (i=3; i<=high; i=i+2)
{
if ((n%i)==0)
{
a_prime = 0;
}
}
return a_prime;
}