Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Program to Convert Radian to Degree in C
Converting radians to degrees is a common mathematical operation in C programming. A radian is the standard unit for measuring angles in mathematics, while degrees are commonly used in everyday applications. The complete angle of a circle is 360 degrees or 2? radians.
Syntax
degree = radian × (180 / ?)
Where ? (pi) ? 3.14159 or can be approximated as 22/7.
Conversion Formula
The mathematical relationship between radians and degrees is −
degree = radian × (180/?) where, ? = 3.14159
For example, if radian = 9.0, then degree = 9.0 × (180/3.14159) = 515.92357
Example: Using Function Approach
This example demonstrates how to convert radians to degrees using a dedicated function −
#include <stdio.h>
#define PI 3.14159
// Function for converting radian to degree
double convert(double radian) {
return (radian * (180.0 / PI));
}
int main() {
double radian = 9.0;
double degree = convert(radian);
printf("Radian: %.2lf<br>", radian);
printf("Degree: %.5lf<br>", degree);
return 0;
}
Radian: 9.00 Degree: 515.92357
Example: Direct Calculation
You can also perform the conversion directly without using a separate function −
#include <stdio.h>
#define PI 3.14159
int main() {
double radian = 1.57; // ?/2 radians
double degree = radian * (180.0 / PI);
printf("%.2lf radians = %.2lf degrees<br>", radian, degree);
return 0;
}
1.57 radians = 90.00 degrees
Key Points
- Use double data type for precise calculations
- Define PI as a macro for better accuracy:
#define PI 3.14159 - Remember: 180 degrees = ? radians
- For very precise calculations, use
math.hlibrary'sM_PIconstant
Conclusion
Converting radians to degrees in C is straightforward using the formula: degree = radian × (180/?). Always use double precision for accurate results and consider using the math.h library for mathematical constants.
