0% found this document useful (0 votes)
10 views

Simple Calculator

pop
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Simple Calculator

pop
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Simulation of a Simple Calculator.

Algorithm:

Step 1: Start

Step 2: Read a and b

Step 3: Read operation

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 8: Print the 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);
}

You might also like