|
Thread: pow
-
Oct 3rd, 2006, 04:02 PM
#1
Thread Starter
Lively Member
pow
Hi,
The following is my code. When I tried to compile it. It give me an error massage "undefined reference to 'pow'. I thought I did include #include <math.h>....
Any idea?
Thanks.
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main(){
int i;
float s, l;
printf("\n\t|----------------------------------------------------|");
printf("\n\t| x | x^2 | cube root of x | x^4 |");
printf("\n\t|----------------------------------------------------|");
for (i=1;i<=100;i++)
{
s = i*i;
l = s*s;
printf("\n\t| %d |",i);
printf(" %5.0f |",s);
printf(" %5.3f |",pow(i,1.0/3.0));
printf(" %5.0f |",l);
printf("\n");
getch();
}
printf("\t|-----------------------------------------------------|");
getch();
}
-
Oct 3rd, 2006, 04:34 PM
#2
Re: pow
As far as I remember, pow() returns a double value, so instead of %f use %lf.
-
Oct 3rd, 2006, 04:40 PM
#3
Thread Starter
Lively Member
Re: pow
still...
/tmp//ccg24629.o: In function `main':
/tmp//ccg24629.o(.text+0xaf): undefined reference to `pow'
collect2: ld returned 1 exit status
-
Oct 3rd, 2006, 05:01 PM
#4
Re: pow
You need to link against the math library, libm. Add -lm to the compiler command line.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 3rd, 2006, 05:38 PM
#5
Thread Starter
Lively Member
Re: pow
like this #include <libm.h>?
I though this #include <math.h> should do it.
-
Oct 3rd, 2006, 05:40 PM
#6
Re: pow
No, not like this. You need to learn the difference between a library file and a header file. I explicitly said 'command line', too, and what you must put there.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 3rd, 2006, 06:24 PM
#7
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|