Possible Duplicate:
Including files in C
I am using RunC to write a simple function which requires pow and floor/truncate. I included math.h. When I use the functions in the main, there is no problems. However, once I try to make a separate int function, suddenly RunC does not have the pow and floor functions and gives me an error. Any help?
Here is the code: main() works, but if I were to switch it to use the function above it doing the exact same thing, it will not work
#include <stdio.h>
#include <math.h>
int sumofsquares(int x){
int counter = 0;
int temp = x;
while (temp != 0 || counter == 100){
//temp = temp - (int)pow(floor(sqrt(temp)), 2);
//temp = temp - pow(temp, 0.5);
printf("%d\n", temp);
counter = counter + 1;
}
/*while(temp != 0){
temp = temp - (int)pow(floor(sqrt(temp)), 2);
counter ++;
}*/
return counter;
}
int main(void){
printf("%d", (int)pow(floor(sqrt(3)), 2));
}
doing this:
#include <stdio.h>
#include <math.h>
int sumofsquares(int x){
int counter = 0;
int temp = x;
while(temp != 0){
temp = temp - (int)pow(floor(sqrt(temp)), 2);
counter ++;
}
return counter;
}
int main(void){
printf("%d", sumofsquares(3));
}
returns this error:
/tmp/cctCHbmE.o: In function `sumofsquares':
/home/cs136/cs136Assignments/a04/test.c:9: undefined reference to `sqrt'
/home/cs136/cs136Assignments/a04/test.c:9: undefined reference to `floor'
collect2: ld returned 1 exit status