Posted on by Kalkicode
Code Conversion

Angular measurement systems play a vital role in mathematics, physics, and engineering. One such system is gradians, which divides a right angle into 100 units. Radians, on the other hand, are a more fundamental angular measurement used extensively in mathematics and physics. Converting angles from gradians to radians is an important task that involves understanding these measurement systems and the relationships between them.

## Problem Statement and Description

The task is to convert an angle given in gradians to its equivalent value in radians. Radians are a unit of angular measurement that relates the angle to the length of the radius of a circle. The formula to convert from gradians to radians is `(gradian * π) / 200`, where π (pi) is a mathematical constant approximately equal to 3.14159. This formula takes the given angle in gradians, multiplies it by π, and then divides by 200 to obtain the equivalent angle in radians.

## Example

Let's take an example to illustrate the problem. Suppose we have an angle of 60 gradians that we want to convert to radians. Using the formula:

``````Radian = (Gradian * π) / 200
Radian = (60 * π) / 200

So, 60 gradians is approximately equal to 0.94248 radians.

## Idea to Solve the Problem

To solve this problem, we need to create a program that takes an angle in gradians as input, applies the conversion formula, and then outputs the equivalent angle in radians. We will use a function to perform this conversion, and the main program will call this function for different test cases.

## Pseudocode

Here's the pseudocode for the program:

``````function gradian_to_radian(gradian):
radian = (gradian * π) / 200
``````

## Algorithm Explanation

1. Define the `gradian_to_radian` function that takes a parameter `gradian`.
2. Inside the function, calculate the equivalent radian using the formula `(gradian * π) / 200`.
3. Return the calculated radian.
4. In the `main` program, call the `gradian_to_radian` function with different test cases: 1, 50.80, and 70.50.
5. Print the results.

## Program Solution

``````//C Program
#include <stdio.h>

#include <math.h>

{
// Formula : (gradian*π)/200
double radian = (gradian * M_PI) / 200;
//Display result
}
int main()
{
//Simple test
return 0;
}``````

#### Output

``````Gradian : 1.000000  radian : 0.015708
``````/*
Java program
*/
class MyMath
{
{
// Formula : (gradian*π)/200
double radian = (gradian * Math.PI) / 200;
System.out.print("Gradian : " + gradian + " radian : " + radian + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1.0 radian : 0.015707963267948967
``````/*
C++ program
*/
#include<iostream>
#include<math.h>
using namespace std;
class MyMath
{
public:
{
// Formula : (gradian*π)/200
double radian = (gradian * M_PI) / 200;
cout << "Gradian : " << gradian << " radian : " << radian << "\n";
}
};
int main()
{
MyMath obj = MyMath();
//Simple test
return 0;
}``````

#### Output

``````Gradian : 1 radian : 0.015708
``````/*
C# program
*/
using System;
class MyMath
{
{
// Formula : (gradian*π)/200
double radian = (gradian * Math.PI) / 200;
Console.Write("Gradian : " + gradian + " radian : " + radian + "\n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1 radian : 0.015707963267949
``````<?php
/*
Php program
*/
class MyMath
{
{
// Formula : (gradian*π)/200
\$radian = (\$gradian * M_PI) / 200;
}
}

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

#### Output

``````Gradian : 1 radian : 0.015707963267949
``````/*
Node Js program
*/
class MyMath
{
{
// Formula : (gradian*π)/200
var radian = (gradian * Math.PI) / 200;
process.stdout.write("Gradian : " + gradian + " radian : " + radian + "\n");
}
}

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

#### Output

``````Gradian : 1 radian : 0.015707963267948967
``````#   Python 3 program
import math
class MyMath :
# Find the radian of given gradian
#  Formula : (gradian*π)/200
radian = (gradian * math.pi) / 200

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

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

#### Output

``````Gradian :  1  radian :  0.015707963267948967
``````#   Ruby program

class MyMath

# Find the radian of given gradian

#  Formula : (gradian*π)/200
radian = (gradian * Math::PI) / 200
end
end
def main()

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

#### Output

``````Gradian : 1 radian : 0.015707963267948967
``````
``````/*
Scala program
*/
class MyMath
{
// Formula : (gradian*π)/200
var radian: Double = (gradian * Math.PI) / 200;
print("Gradian : " + gradian + " radian : " + radian + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1.0 radian : 0.015707963267948967
``````/*
Swift program
*/
import Foundation
class MyMath
{
{
// Formula : (gradian*π)/200
let radian: Double = (gradian * Double.pi) / 200;
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
}
main();``````

#### Output

``````Gradian :  1.0  radian :  0.015707963267949

## Time Complexity

Similar to the previous problem, the time complexity of this program is constant for each conversion. It involves basic arithmetic operations like multiplication and division, and the number of operations remains consistent regardless of the input gradians. 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