Is there a function in C language to calculate degrees/radians?

There is no need to use such a method. Converting to degrees is very simple:

double radians = 2.0;
double degrees = radians * 180.0 / M_PI;

Turn that into a function if you want to.

M_PI is* defined in math.h by the way.


* in most compilers.


If your preference is to just copy/paste a couple of macros:

#include <math.h>
#define degToRad(angleInDegrees) ((angleInDegrees) * M_PI / 180.0)
#define radToDeg(angleInRadians) ((angleInRadians) * 180.0 / M_PI)

And if you want to omit the #include, replace that line with this which was copied from the math.h header:

#define M_PI   3.14159265358979323846264338327950288

#include <math.h>

inline double to_degrees(double radians) {
    return radians * (180.0 / M_PI);
}

Tags:

C