Square root and cube root of a number

This is program of Switch Case in which we are going to calculate Square root and Cube root of a number in C Programming.

#include <stdio.h>
#include <math.h>

int main()
{
    float num, result;
    char input; 
    printf("Enter a number:- ");
    scanf("%f", &num);
    printf("Enter 'S' for Square-root & 'C' for Cube-root\n");
    scanf(" %c", &input);

    switch (input) //2 cases of same alphabet because of Case sensitive.
    {
    case 's':
        result = sqrt(num);
        printf("Square root of the given number is :- %f", result);
        break;

    case 'S':
        result = sqrt(num);
        printf("Square root of the given number is :- %f", result);
        break;
    
    case 'c':
        result = cbrt(num);
        printf("Cube root of the given number is :- %f", result);
        break;

    case 'C':
        result = cbrt(num);
        printf("Cube root of the given number is :- %f", result);
        break;

    default:
        printf("Oops!!! Looks like you have entered an invalid input, Please Try again.");
        break;
    }

    return 0;
}
//.............Coded by YASH ALLAPURIA

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post