Simple C program for radians to degrees calculator - The Idle Coder

Simple C program for radians to degrees calculator


Hello friends... In this tutorial we will make a simple program for radians to degrees calculator. It is not the full radians to degrees calculator. But here we will make a simple demo program for the calculator. In this post we will simultaneously converts radians to degree and degree to radians. The
program given below is containing both options for simple conversions.


Simple Program for radians to degrees and degrees to radians calculator using c language

Code:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define _USE_MATH_DEFINES
 #define PI 3.14159265

float DegreesToRadians(float degrees);
float RadiansToDegrees(float radians);

int main(void)
{
    int exit = 0, option = 0;
    float degrees = 0, radians = 0, angle = 0;
    while (exit == 0)
    {
        system("opt");
        printf("\n Kindly select perticuler option: "
               "\n\t[1] go for degrees to radians"
               "\n\t[2] go for radians to degrees"
               "\n\t[0] Stop the program\n");
        scanf("%d",&option);
        switch (option)
        {
        case 1:
            printf("\n Enter angle in degree: ");
            scanf("%f",&degrees);
            angle = DegreesToRadians(degrees);
            printf(" The desired angle in radians for given degree:
%.4f",angle);
            getch();
            break;
        case 2:
            printf("\n Enter angle in radions: ");
            scanf("%f",&radians);
            angle = RadiansToDegrees(radians);
            printf(" The desired angle in degree for given radians:
%.4f",angle);
            getch();
            break;
        case 0:
            exit = 1;
            break;
        default:
            printf("\nNot found please check it.");
            getch();
            break;
        }
    }
    printf("\n\nClick on any key to stop...");
    getch();
    return 0;
}

Output of radians to degrees and degrees to radians:



rradians to degrees calculator



In this program the user will be asked to give particular input. As per the input given by the user, the output will be generated by program. There are three options in the program. First one converts degrees to radians, second one converts radians to degree and with the help of last one you can simply exit from the program. So in this way you can make a simple calculator of radians to degree and the same degrees to radians easily. Stay connected for more programming stuff.

Previous
Next Post »