Posted on by Kalkicode
Code Conversion

In geometry and trigonometry, angles are often measured in degrees. However, there are other angular measurement systems as well, such as radians and gradians. Gradians, also known as gon or grad, is an angular measurement system where a right angle is divided into 100 gradians, much like how a degree is divided into 60 minutes. Converting between different angular units is a common task, especially when working with various mathematical and scientific applications.

## Problem Statement and Description

The problem at hand is to convert an angle given in gradians to its equivalent value in degrees. The formula to convert from gradians to degrees is `(gradian * 180) / 200`. This formula takes the given angle in gradians, multiplies it by 180, and then divides by 200 to obtain the equivalent angle in degrees.

## Example

Let's take an example to understand the problem better. Suppose we have an angle of 50 gradians that we want to convert to degrees. Using the formula:

``````Degree = (Gradian * 180) / 200
Degree = (50 * 180) / 200
Degree = 45``````

So, 50 gradians is equivalent to 45 degrees.

## Idea to Solve the Problem

To solve this problem, we need to implement a program that takes a value in gradians as input, applies the conversion formula, and then outputs the equivalent angle in degrees. 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_degree(gradian):
degree = (gradian * 180) / 200
return degree
``````

## Algorithm Explanation

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

## Code Solution

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

#include <math.h>

//Find the degree of given gradian
{
// Calculate given gradian to degree
double degree = (gradian * 180) / 200;
//Display result
}
int main()
{
//Simple test
return 0;
}``````

#### Output

``````Gradian : 1.000000  Degree : 0.900000
Gradian : 70.800000  Degree : 63.720000
Gradian : 1000.500000  Degree : 900.450000``````
``````/*
Java program
*/
class MyMath
{
//Find the degree of given gradian
{
// Calculate given gradian to degree
double degree = (gradian * 180) / 200;
System.out.print("Gradian : " + gradian + " Degree : " + degree + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1.0 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````/*
C++ program
*/
#include<iostream>

using namespace std;
class MyMath
{
public:
//Find the degree of given gradian
{
// Calculate given gradian to degree
double degree = (gradian * 180) / 200;
cout << "Gradian : " << gradian << " Degree : " << degree << "\n";
}
};
int main()
{
MyMath obj = MyMath();
//Simple test
return 0;
}``````

#### Output

``````Gradian : 1 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````/*
C# program
*/
using System;
class MyMath
{
//Find the degree of given gradian
{
// Calculate given gradian to degree
double degree = (gradian * 180) / 200;
Console.Write("Gradian : " + gradian + " Degree : " + degree + "\n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````<?php
/*
Php program
*/
class MyMath
{
//Find the degree of given gradian
{
// Calculate given gradian to degree
\$degree = (\$gradian * 180) / 200;
}
}

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

#### Output

``````Gradian : 1 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````/*
Node Js program
*/
class MyMath
{
//Find the degree of given gradian
{
// Calculate given gradian to degree
var degree = (gradian * 180) / 200;
process.stdout.write("Gradian : " + gradian + " Degree : " + degree + "\n");
}
}

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

#### Output

``````Gradian : 1 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````#   Python 3 program

class MyMath :
# Find the degree of given gradian
#  Calculate given gradian to degree
degree = (gradian * 180) / 200
print("Gradian : ", gradian ," Degree : ", degree ,"\n", end = "")

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

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

#### Output

``````Gradian :  1  Degree :  0.9
Gradian :  70.8  Degree :  63.72
Gradian :  1000.5  Degree :  900.45``````
``````#   Ruby program

class MyMath

# Find the degree of given gradian

#  Calculate given gradian to degree
degree = (gradian * 180) / 200
end
end
def main()

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

#### Output

``````Gradian : 1 Degree : 0
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45
``````
``````/*
Scala program
*/
class MyMath
{
//Find the degree of given gradian
// Calculate given gradian to degree
var degree: Double = (gradian * 180) / 200;
print("Gradian : " + gradian + " Degree : " + degree + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
}
}``````

#### Output

``````Gradian : 1.0 Degree : 0.9
Gradian : 70.8 Degree : 63.72
Gradian : 1000.5 Degree : 900.45``````
``````/*
Swift program
*/
class MyMath
{
//Find the degree of given gradian
{
// Calculate given gradian to degree
let degree: Double = (gradian * 180) / 200;
print("Gradian : ", gradian ," Degree : ", degree ,"\n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
}
main();``````

#### Output

``````Gradian :  1.0  Degree :  0.9
Gradian :  70.8  Degree :  63.72
Gradian :  1000.5  Degree :  900.45``````

## Time Complexity

The time complexity of this program is constant for each conversion, as it involves only basic arithmetic operations like multiplication and division. Regardless of the value of the input gradians, the number of operations remains the same. Therefore, the time complexity can be considered 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