You are here:

C/C cosine function

Advertisement


Question
I am trying to take the cosine of a changing integer and have it printed as a list for a certain number of integers.  I have the #include<math.h> statement in, and I have a line that says double cos(double x); but whenever I try to compile my program I get an error that says Unresolved: cos  - I am very confused. I have looked all over online and have worked on this for a long time, but I can't get it to take the cosine in any form, even outside of my iterating loop.  I tried defining Pi=3.14159... and evaluating cos(Pi) and printing just that, but it won't even do that.  Can you help?  Thanks.

Answer
<math.h> is the header file which contains all the related declarations.
But the actual definitions are present in the library - libmath.h
You will have to compile with that library.
So, your compilation command will become:
gcc -o myprog myprog.c -lm

Note that the flag -lm is for compiling with math library.

-Narendra

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.