In this example, we are going to create simple calculator application in c programming.
#include<stdio.h>
int main() {
char operator;
float num1,num2;
printf("Enter two numbers as operands\n");
scanf("%f%f", &num1, &num2);
printf("Enter an arithemetic operator(+-*/)\n");
scanf("%*c%c",&operator);
switch(operator) {
case '+':
printf("%.2f + %.2f = %.2f",num1, num2, num1+num2);
break;
case '-':
printf("%.2f - %.2f = %.2f",num1, num2, num1-num2);
break;
case '*':
printf("%.2f * %.2f = %.2f",num1, num2, num1*num2);
break;
case '/':
printf("%.2f / %.2f = %.2f",num1, num2, num1/num2);
break;
default:
printf("ERROR: Not Valid Operatior");
}
return 0;
}
Output :
Enter two numbers as operands
10
20
Enter an arithemetic operator(+-*/)
+
10.00 + 20.00 = 30.00
Ask anything about this examples