Be seen. Boost your questionâ€™s priority for more expert views and faster solutions

I would like to calculate the sine cosine and tangent of some numbers. What are the functions that let me to do that? I am new to C++ and English so please be clear. Thank you.

sin

cos

tan

For the arc sine, arc cosine, and arc tangent look into:

asin

acos

atan

All of these functions are declared in the "math.h" header file, so make sure you add:

#include <math.h>

to the top of your source code.

Also, remember that the numbers you provide the function are in radians, not degrees. To convert from degrees to radians, multiply the number of degrees by:

0.01745329252 (roughly) :-)

Here's an example.

Let's say you want to calculate the sine of 234 (degrees). You would use:

result = sin (234 * 0.01745329252);

Consider definining a constant double at the top of the source code that looks like:

const double DEG2RAD 0.01745329252;

or something like that. That way, you don't have to remember those arcane numbers.

Here is an example that uses the DEG2RAD constant:

sin (234 * DEG2RAD);

See how much easier that is to read?

If you have any additional questions, please ask.

const double DEG2RAD = 0.01745329252;

Good answer otherwise

BTW the maths relies on 2 * PI radians in 360 degrees

Hippy.

"

Here are the names of the functions that do what you ask:

sin

cos

tan

For the arc sine, arc cosine, and arc tangent look into:

asin

acos

atan

All of these functions are declared in the "math.h" header file, so make sure you add:

#include <math.h>

to the top of your source code.

Also, remember that the numbers you provide the function are in radians, not degrees.Â Â To convert from degrees to radians, multiply the number of degrees by:

0.01745329252 (roughly)Â Â :-)

Here's an example.

Let's say you want to calculate the sine of 234 (degrees).Â Â You would use:

result = sin (234 * 0.01745329252);

Consider definining a constant double at the top of the source code that looks like:

const double DEG2RAD 0.01745329252;

or something like that.Â Â That way, you don't have to remember those arcane numbers.

Here is an example that uses the DEG2RAD constant:

sin (234 * DEG2RAD);

See how much easier that is to read?

If you have any additional questions, please ask.

"

daitt - It is usually considered bad form to "answer" a question using someone else's comments. I cannot use EE to the same extent that I used to be able to (only able to log on about once a day for half hour to hour) because I have school and a life. That means it might take me some time to respond to comments. Please see my profile.

nietod - I think I am going to go back to actually answering questions again. I was just giving the "answer-in-comment" approach a try because it would keep the question open so the customer could get more response from other experts. It's unfortunate that people "answer" the question with someone else's comment(s).

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.