Created
March 17, 2019 08:59
-
-
Save rk4bir/06b47308c9e0fe6848784b6e37b2436a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main(){ | |
float x,y; | |
char ch, escape; | |
printf("Enter x & y\n"); | |
scanf("%f %f", &x, &y); | |
/* | |
Automatically a new line character input is made by the c-program itself. | |
To prevent the unexpected input messing our program, we placed the | |
escape char variable to hold that unexpected value. | |
[ NB: There are several way you can handle this problem. ] | |
*/ | |
scanf("%c", &escape); | |
printf("Which operation you want to perform? [+, -, / or *]\n"); | |
scanf("%c", &ch); | |
switch(ch){ | |
case '+': | |
printf("%.2f + %.2f = %.2f\n", x, y, x+y); | |
break; | |
case '-': | |
printf("%.2f - %.2f = %.2f\n", x, y, x-y); | |
break; | |
case '*': | |
printf("%.2f x %.2f = %.2f\n", x, y, x*y); | |
break; | |
case '/': | |
printf("%.2f / %.2f = %.2f\n", x, y, x/y); | |
break; | |
default: | |
printf("Invalid operation\n"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment