Sunday, 12 December 2010

Algorithm for evaluate an expression like caliculator

Objective:7

Two integer operands and one operator form user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use Switch Statement)

Description:


To take the two integer operands and one operator from user to perform the some arithmetic operations by using the following operators like +,-,*, /, %
Ex: 2+3=5



Step 1: Start

Step 2: Read the values of a,b and operator
Step 3: if the operator is ‘+’ then
a=a+b
Go to step 8
Break

Step 4: Else if the operator is ‘-‘ then
a=a-b
Go to step 8

Step 5: Else if the operator is ‘*‘ then
a=a*b
Go to step 8

Step 6: Else if the operator is ‘/‘ then
a=a/b
Go to step 8

Step 7: Else if the operator is ‘%‘ then
a=a%b
Go to step 8

Step 8: write a

Step 9:End

No comments:

Post a Comment