This blog is under construction

Monday 30 April 2012

atan2 example in C

Header file:
    math.h

Synopsis:
     double atan2(double y, double x);

Description:
     Returns principal value of the arc tangent of y/x.


atan2 function in C example


  #include<stdio.h>
  #include<math.h>
  int main() {
        /*
         * radian to degree conversion
         * degree = radian * 180 / PI;
         */
  
      double deg, x , y;
        printf("Enter your input for x & y:");
        scanf("%lf%lf", &x, &y);
        deg = atan2(y, x) * (180 / 3.14);
        printf("Degree: %lf\n", deg);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/math$ gcc atan2.c -lm
  jp@jp-VirtualBox:~/cpgms/math$ ./a.out
  Enter your input for x & y:1 1
  Degree: 45.022825



No comments:

Post a Comment