We will discuss trigonometric and hyperbolic Math functions. All these functions which takes angle as input are in radian. Similarly arc functions gives return values in radian. In practical cases we take angle in degrees thus we used macro to convert degree to radian and radian to degree.

Trigonometric functions

  • cos - Compute cosine double sin(double);
  • sin - Compute sine double cos(double);
  • tan - Compute tangent double tan(double);
  • acos - Compute arc cosine double acos(double);
  • asin - Compute arc sine double asin(double);
  • atan - Compute arc tangent double atan(double);
  • atan2 - Compute arc tangent with two parameters double atan2(double, double);

Hyperbolic functions

  • cosh Compute hyperbolic cosine double cosh(double);
  • sinh Compute hyperbolic sine double sinh(double);
  • tanh Compute hyperbolic tangent double tanh(double);

#include<stdio.h>
#include<math.h>

#define DEG2RAD(x) (double)(22*x)/(7*180)
#define RAD2DEG(x) (double)(*180 *7)/22

int main (int argc, char * argv[])
{
  printf ("sin(%d) = %.2lf\n", 30, sin(DEG2RAD(30)));
  printf ("cos(%d) = %.2lf\n", 60, cos(DEG2RAD(60)));
  printf ("tan(%d) = %.2lf\n", 45, tan(DEG2RAD(45)));

  printf ("asin(%.2f) = %.0lf\n", 0.5f, RAD2DEG(asin((double)0.5)));
  printf ("acos(%.2f) = %.0lf\n", 0.5f, RAD2DEG(acos((double)0.5)));
  printf ("atan(%.2f) = %.0lf\n", 1.0f, RAD2DEG(atan((double)1)));
  printf ("atan2(%.2f/%.f) = %.0lf\n", sqrt(3), 3.0f, RAD2DEG(atan2((double)sqrt(3),3)));

}

output

sin(30) = 0.50
cos(60) = 0.50
tan(45) = 1.00
asin(0.50) = 30
acos(0.50) = 60
atan(1.00) = 45
atan2(1.73/3) = 30

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.

#