Posted on by Kalkicode
Code Conversion

# Convert radian to degree

The problem at hand involves the conversion of angles from radians to degrees. Angles can be measured in different units, with radians and degrees being two commonly used units. Radians are based on the radius of a circle, while degrees divide a circle into 360 equal parts. Converting between these units is a fundamental operation in mathematics and finds applications in various fields such as physics, engineering, and computer science.

## Problem Statement

Given an angle in radians, we want to convert it into degrees. The goal is to create a C program that performs this conversion for any given input angle in radians and provides the result in degrees.

## Explanation with Examples

Let's consider a few examples to better understand the problem. Suppose we have the following angles in radians: 1, 7.8, and 10.5.

• For an angle of 1 radian:

Using the formula `(radian * 180) / π`, we get `(1 * 180) / π ≈ 57.295780` degrees.

• For an angle of 7.8 radians

Applying the formula, we have `(7.8 * 180) / π ≈ 446.907080` degrees.

• For an angle of 10.5 radians

By plugging in the value, we get `(10.5 * 180) / π ≈ 601.605685` degrees.

## Idea to Solve the Problem

To solve this problem, we can follow these steps:

1. Take an input angle in radians.
2. Apply the conversion formula `(radian * 180) / π` to convert radians to degrees.
3. Display the input angle in radians along with the converted angle in degrees.

## Pseudocode

``````function radian_to_degree(radian):
degree = (radian * 180) / π
display "Radian :", radian, " Degree :", degree
``````

## Algorithm Explanation

1. The `radian_to_degree` function takes a single argument `radian`, which represents the angle in radians.
2. Inside the function, the conversion formula is applied: `degree = (radian * 180) / π`.
3. The result is displayed using the `printf` function.

## Program Solution

``````//C Program
//Convert radian to degree
#include <stdio.h>

#include <math.h>

//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
double degree = (radian * 180) / M_PI;
//Display result
printf("Radian : %lf  Degree : %lf\n", radian, degree);
}
int main()
{
//Simple test
return 0;
}``````

#### Output

``````Radian : 1.000000  Degree : 57.295780
Radian : 7.800000  Degree : 446.907080
Radian : 10.500000  Degree : 601.605685``````
``````/*
Java program
Convert radian to degree
*/
class MyMath
{
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
double degree = (radian * 180) / Math.PI;
System.out.print("Radian : " + radian + " Degree : " + degree + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Radian : 1.0 Degree : 57.29577951308232
Radian : 7.8 Degree : 446.9070802020421
Radian : 10.5 Degree : 601.6056848873644``````
``````/*
C++ program
Convert radian to degree
*/
#include<iostream>
#include<math.h>
using namespace std;
class MyMath
{
public:
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
double degree = (radian * 180) / M_PI;
cout << "Radian : " << radian << " Degree : " << degree << "\n";
}
};
int main()
{
MyMath obj = MyMath();
//Simple test
return 0;
}``````

#### Output

``````Radian : 1 Degree : 57.2958
Radian : 7.8 Degree : 446.907
Radian : 10.5 Degree : 601.606``````
``````/*
C# program
Convert radian to degree
*/
using System;
class MyMath
{
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
double degree = (radian * 180) / Math.PI;
Console.Write("Radian : " + radian + " Degree : " + degree + "\n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Radian : 1 Degree : 57.2957795130823
Radian : 7.8 Degree : 446.907080202042
Radian : 10.5 Degree : 601.605684887364``````
``````<?php
/*
Php program
Convert radian to degree
*/
class MyMath
{
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
\$degree = (\$radian * 180) / M_PI;
echo "Radian : ". \$radian ." Degree : ". \$degree ."\n";
}
}

function main()
{
\$obj = new MyMath();
//Simple test
}
main();``````

#### Output

``````Radian : 1 Degree : 57.295779513082
Radian : 7.8 Degree : 446.90708020204
Radian : 10.5 Degree : 601.60568488736``````
``````/*
Node Js program
Convert radian to degree
*/
class MyMath
{
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
var degree = (radian * 180) / Math.PI;
process.stdout.write("Radian : " + radian + " Degree : " + degree + "\n");
}
}

function main()
{
var obj = new MyMath();
//Simple test
}
main();``````

#### Output

``````Radian : 1 Degree : 57.29577951308232
Radian : 7.8 Degree : 446.9070802020421
Radian : 10.5 Degree : 601.6056848873644``````
``````#   Python 3 program
#   Convert radian to degree
import math
class MyMath :
# Find the degree of given radian
#  Formula : (radian*180)/π
#  Calculate given radian to degree
degree = (radian * 180) / math.pi
print("Radian : ", radian ," Degree : ", degree ,"\n", end = "")

def main() :
obj = MyMath()
# Simple test

if __name__ == "__main__": main()``````

#### Output

``````Radian :  1  Degree :  57.29577951308232
Radian :  7.8  Degree :  446.9070802020421
Radian :  10.5  Degree :  601.6056848873644``````
``````#   Ruby program
#   Convert radian to degree

class MyMath

# Find the degree of given radian

#  Formula : (radian*180)/π
#  Calculate given radian to degree
degree = (radian * 180) / Math::PI
print("Radian : ", radian ," Degree : ", degree ,"\n")
end
end
def main()

obj = MyMath.new()
# Simple test
end
main()``````

#### Output

``````Radian : 1 Degree : 57.29577951308232
Radian : 7.8 Degree : 446.9070802020421
Radian : 10.5 Degree : 601.6056848873644
``````
``````/*
Scala program
Convert radian to degree
*/
class MyMath
{
//Find the degree of given radian
// Formula : (radian*180)/π
// Calculate given radian to degree
var degree: Double = (radian * 180) / Math.PI;
print("Radian : " + radian + " Degree : " + degree + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
}
}``````

#### Output

``````Radian : 1.0 Degree : 57.29577951308232
Radian : 7.8 Degree : 446.9070802020421
Radian : 10.5 Degree : 601.6056848873644``````
``````/*
Swift program
Convert radian to degree
*/
import Foundation
class MyMath
{
//Find the degree of given radian
{
// Formula : (radian*180)/π
// Calculate given radian to degree
let degree: Double = (radian * 180) / Double.pi;
print("Radian : ", radian ," Degree : ", degree ,"\n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
}
main();``````

#### Output

``````Radian :  1.0  Degree :  57.2957795130823
Radian :  7.8  Degree :  446.907080202042
Radian :  10.5  Degree :  601.605684887364``````

## Time Complexity

The time complexity of this code is constant for each conversion, as it involves only a few arithmetic operations and a print statement. Thus, the time complexity is O(1).

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

Categories
Relative Post