What's wrong ?

What’s wrong in this simple code ?

#include<math.h>
#include<stdio.h>
#define pi 3.1406
#define max 180
int main()
{
int angle;
float x,y;
angle=0;
printf(" Angle cos(angle)

“);
while(angle<=max)
{
x=(pi/max)*angle;
y= cos(x);
printf(”%15d %13.4f
",angle,y);
angle=angle+10;
}
return 0;
}

Error is
cc first.c
/tmp/ccrCUfIm.o: In function main': first.c:(.text+0x3b): undefined reference to cos’
collect2: ld returned 1 exit status

Any ideas ?

Nothing is wrong with the above C program. What is wrong is not including the math library “-lm” when you compile. It’s a linker option, “-llibrary”. See man cc or #cc in konqueror.

cc first.c -lm

Here is the output
cc first.c -lm
/tmp/ccs6xrnu.o: In function main': first.c: (.text+0x3b): undefined reference to Cos’
collect2: ld returned 1 exit status

thanks it worked… I had written ‘Cos’ instead of ‘cos’…)

Option is -lm (dash el em), it really works.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could probably define ‘pi’ quite a bit closer too…

3.14159265

Good luck.

tanmaya wrote:
| thanks it worked… I had written ‘Cos’ instead of ‘cos’…)
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIV08V3s42bA80+9kRArp9AKCI3Cutu/pARcRL2Q1yT5HJTiz1KwCff7jq
joLcvFNvdAPcR/FF4hZaOpw=
=dfXg
-----END PGP SIGNATURE-----

yes i defined the value of pi more accurately and the results are bit different this time

Please, next time you make such a post, can you make the Title more descriptive? “Whats wrong?” is not helpful as a Title.

Thank-you.

i will take care of this mistake next time