#include<stdio.h>
int main()
{
float value1, value2;
char operator;
printf("Type in your expression. \n");
scanf("%f%c%f",&value1,&operator,&value2);
switch(operator)
{
case '+': printf("%f \n", value1 + value2);
break;
case '-': printf("%f \n", value1 - value2);
break;
case '*': printf("%f \n", value1 * value2);
break;
case '/': if(value2 == 0)
printf("division by zero. \n");
else
printf("%f \n", value1 / value2);
break;
default: printf("Unknown Operator \n");
break;
}
getch();
return 0;
}
<b>Output 1:</b>
Type in your expression.
2+3
5.000000
<b>Output 2:</b>
Type in your expression.
6*2
12.000000
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.