Created
September 17, 2018 06:53
-
-
Save simplyniceweb/03b82d267a499d66e34d724ed68d4a6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <conio.h> | |
float formula(float x, float y, int z); | |
void main() | |
{ | |
int choice; | |
float num1,num2; | |
printf("1-Addition"); | |
printf("\n2-Subtraction"); | |
printf("\n3-Multiplication"); | |
printf("\n4-Division"); | |
printf("\n1st Number: "); | |
scanf("%f",&num1); | |
printf("2nd Number: "); | |
scanf("%f",&num2); | |
printf("Type of Operation: "); | |
scanf("%d",&choice); | |
switch(choice) { | |
case 1: | |
printf("%.0f+%.0f=%.0f", num1, num2, formula(num1, num2, choice)); | |
break; | |
case 2: | |
printf("%.0f-%.0f=%.0f", num1, num2, formula(num1, num2, choice)); | |
break; | |
case 3: | |
printf("%.0f*%.0f=%.0f", num1, num2, formula(num1, num2, choice)); | |
break; | |
case 4: | |
printf("%0.f/%.0f=%.1f", num1, num2, formula(num1, num2, choice)); | |
break; | |
} | |
} | |
float formula(float x,float y, int z) { | |
switch(z) { | |
case 1: | |
return x + y; | |
break; | |
case 2: | |
return x - y; | |
break; | |
case 3: | |
return x * y; | |
break; | |
case 4: | |
return x / y; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment