Quote:
Originally posted by loke137
Isn`t sqrt defined in math.h??
|
Well, yes, it is. But in case of the math library, you also need to
link with the math
library. It's very understandable that you, as a beginner, didn't know this as for most standard things you #include there's no need for linking with seperate libraries.
Assuming you c-file is called "prime.c", and you want the executable be called "prime", compile with this command line
Code:
gcc -lm -o prime prime.c
"-lm" makes sure the math library is linked.
You'll also see another error, because you forgot to pass the variable i to the printf statement. Change the line to:
Code:
printf ("%d\n", i);
Also, it's better to declare main() as "
int main()". If you don't specify "int" as the return type of main(), you'll get a warning. Not a big deal though, it's only warning, not an error.
Compile with this to make the compiler report all possible warnings:
Code:
gcc -Wall -pedantic -lm -o prime prime.c