This is program of Switch Case in which we are going to calculate Square and Cube of a number in C Programming.
#include <stdio.h>
#include <math.h>
int main()
{
double num, result;
char input;
printf("Enter a number:- ");
scanf("%lf", &num);
printf("Enter 'S' for Square & 'C' for Cube\n");
scanf(" %c", &input);
switch (input) //2 cases of same alphabet because of Case sensitive.
{
case 's':
result = num * num;
printf("%lf", result);
break;
case 'S':
result = num * num;
printf("%lf", result);
break;
case 'c':
result = num * num * num;
printf("%lf", result);
break;
case 'C':
result = num * num * num;
printf("%lf", 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