Program to Convert Radian to Degree
Last Updated :
30 Mar, 2023
Before moving to the actual solution, let’s try to find out what is a degree, a radian, and their relations.
Radian: The radian is the standard unit of angular measure, used in many areas of mathematics. The length of an arc of a unit circle is numerically equal to the measurement in radians of the angle that it subtends. One radian is just under 57.3 degrees.
Degree: A degree (in full, a degree of arc, arc degree, or arcdegree), usually denoted by ° (the degree symbol), is a measurement of a plane angle, defined so that a full rotation is 360 degrees.
The relation 2pi*rad = 360° can be derived using the formula for arc length.
An arc of a circle with the same length as the radius of that circle subtends an angle of 1 radian. The circumference subtends an angle of 2pi radians.
Therefore the formula is:
degree = radian * (180/pi)
where, pi = 22/7
Examples:
Input : radian = 20
Output : degree = 1145.4545454545455
Explanation: degree = 20 * (180/pi)
Input : radian = 5
Output : degree = 286.3636363636364
Explanation : degree = 5 * (180/pi)
Note: In this programs, we have taken the value of pi as 3.14159 to get standard result in all three languages.
C++
#include <iostream>
using namespace std;
double Convert( double radian)
{
double pi = 3.14159;
return (radian * (180 / pi));
}
int main()
{
double radian = 5.0;
double degree = Convert(radian);
cout << degree;
return 0;
}
|
C
#include <stdio.h>
double Convert( double radian){
double pi = 3.14159;
return (radian * (180/pi));
}
int main(){
double radian = 5.0;
double degree = Convert(radian);
printf ( "%.5lf" , degree);
return 0;
}
|
Java
import java.io.*;
class GFG {
static double Convert( double radian){
double pi = 3.14159 ;
return (radian * ( 180 /pi));
}
public static void main (String[] args) {
double radian = 5.0 ;
double degree = Convert(radian);
System.out.println( "degree = " + degree);
}
}
|
Python3
def Convert(radian):
pi = 3.14159
degree = radian * ( 180 / pi)
return degree
radian = 5
print ( "degree =" ,(Convert(radian)))
|
C#
using System;
class GFG {
static double Convert( double radian){
double pi = 3.14159;
return (radian * (180 / pi));
}
public static void Main () {
double radian = 5.0;
double degree = Convert(radian);
Console.Write( "degree = " + degree);
}
}
|
PHP
<?php
function Convert( $radian )
{
$pi = 3.14159;
return ( $radian * (180 / $pi ));
}
$radian = 5.0;
$degree = Convert( $radian );
echo ( $degree );
?>
|
Javascript
<script>
function Convert(radian){
let pi = 3.14159;
return (radian * (180/pi));
}
let radian = 5.0;
let degree = Convert(radian);
document.write(degree);
</script>
|
Time Complexity: O(1), as we are not using any loops.
Auxiliary Space: O(1), as we are not using any extra space.
Example :
The following program demonstrates toDegree() and toRadians().
C++
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double theta = 120.0;
cout << theta << " degree is " << (theta * M_PI / 180) << " radians." << endl;
theta = 1.312;
cout << theta << " radians is " << (theta * 180 / M_PI) << " degrees." << endl;
return 0;
}
|
Java
class GFG{
public static void main(String args[]){
double theta = 120.0 ;
System.out.println(theta+ " degree is " + Math.toRadians(theta)+ " radians." );
theta = 1.312 ;
System.out.println(theta+ " radians is " + Math.toDegrees(theta)+ " degrees." );
}
}
|
Python3
import math
theta = 120.0 ;
print (theta, "degree is" , math.radians(theta), "radians." );
theta = 1.312 ;
print (theta, "radians is " , math.degrees(theta), "degrees." );
|
Javascript
function degreesToRadians(degrees) {
return degrees * Math.PI / 180;
}
function radiansToDegrees(radians) {
return radians * 180 / Math.PI;
}
const theta = 120.0;
console.log(`${theta} degree is ${degreesToRadians(theta)} radians.`);
const radians = 1.312;
console.log(`${radians} radians is ${radiansToDegrees(radians)} degrees.`);
|
C#
using System;
class MainClass {
public static void Main( string [] args)
{
double theta = 120.0;
Console.WriteLine(theta + " degree is "
+ (theta * Math.PI / 180)
+ " radians." );
theta = 1.312;
Console.WriteLine(theta + " radians is "
+ (theta * 180 / Math.PI)
+ " degrees." );
}
}
|
Output
120.0 degree is 2.0943951023931953 radians.
1.312 radians is 75.17206272116401 degrees.
Time Complexity: O(1), as it is using constant operations
Auxiliary Space: O(1), as it is using constant variables
Reference:
https://en.wikipedia.org/wiki/Radian
https://en.wikipedia.org/wiki/Degree_(angle)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...