Simple Calculator
Simple Calculator
Algorithm:
Step 1: Start
Step 4: If choice is equal to plus, add a and b and store the sum in result
Step 5: If choice is equal to minus, subtract b from a and store the difference in result
Step 6: If choice is equal to multiplication multiply a and b and store the product in result
Step 7: If choice is equal to division divide a by b and store the quotient in result
Step 9: Stop
Program
#include<stdio.h>
void main()
{
char operation;
int a,b,result;
printf ("Enter any two operands to perform the operation \n”);
scanf(“%d %d”,&a,&b);
printf ("Enter any one of the operator ( +, -, *, / ) \n”);
scanf(“ %c”,&operation);
switch(operation)
{
case ‘+’ : result =a+b;
break;
case ‘-’ : result =a - b;
break;
case ‘*’ : result =a*b;
break;
case ‘/’ : result =a / b;
break;
default : printf(“Invalid operator”);
}
printf(“The result of %d % c %d = %d”,a, operation, b, result);
}