Program 1:
C program to implement Simulation of a Simple Calculator.
Algorithm
Step-1: Start
Step-2: Read 2 inputs a and b
Step-3: Display the options
Step-4: Read the input choice
Step-5: If Choice is
1 then execute step 6
2 then execute step 7
3 then execute step 8
4 then execute step 9
5 then execute step 10
6 then exit
Other than above mentioned choice than execute step 12
Step-6: Addition of a and b and print res
Step-7: Subtraction of a and b and print res
Step-8: Multiplication of a and b and print res
Step-9: Division of a and b and print res
Step -10: Modulus of a and b and print res
Step -11: Exit the program
Step-12: Invalid choice
Step-13: Stop
Flow Chart
Program:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,res;
char op;
printf(" Simulation of Calculator\n");
printf(" +: Addition\n -: Subtraction\n *: Multiplication\n /:.Division\n
%:.Modulus\n “);
printf("Enter the values of a operator b: \n");
scanf("%d%c%d",&a,&op,&b);
switch(op)
{
case '+': res=a+b;
break;
case '-': res=a-b;
break;
case '*':res=a*b;
break;
case '/':if( b==0)
{
printf(" Cannot divide\n");
exit(0);
}
else
res=a/b;
break;
case '%':res=a%b;
break;
default : printf(" Invalid operator.\n");
exit(0); }
printf("The result of %d %c %d = %d", a,op,b,res);
return 0;
}