C Program To Make A Simple Calculator
C Program To Make A Simple Calculator
This program takes an arithmetic operator +, -, *, / and two operands from the user
and performs the calculation on the two operands depending upon the operator
entered by the user.
# include <stdio.h>
int main() {
char operator;
double firstNumber,secondNumber;
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber +
secondNumber);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber -
secondNumber);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber *
secondNumber);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber /
secondNumber);
break;
return 0;
}
Output
4.5
Since, the operator * matches the case case '*':, the control of the program jumps to