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

Evaluate An Expression Like Caliculator: Objective

The document describes a program that evaluates arithmetic expressions using integer operands and operators. The program takes two integer operands and one operator as input from the user, performs the arithmetic operation based on the operator, and prints the result. It uses a switch statement to handle the different operators (+, -, *, /, %) and performs the corresponding operation on the operands (addition, subtraction, multiplication, division, modulo). It then prints the final result. The program is tested on some sample inputs and outputs to demonstrate its functionality.

Uploaded by

Netaji Gandi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Evaluate An Expression Like Caliculator: Objective

The document describes a program that evaluates arithmetic expressions using integer operands and operators. The program takes two integer operands and one operator as input from the user, performs the arithmetic operation based on the operator, and prints the result. It uses a switch statement to handle the different operators (+, -, *, /, %) and performs the corresponding operation on the operands (addition, subtraction, multiplication, division, modulo). It then prints the final result. The program is tested on some sample inputs and outputs to demonstrate its functionality.

Uploaded by

Netaji Gandi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

evaluate an expression like caliculator

//evaluate an expression like caliculator


Objective:
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
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
char op;
printf("etner expression terminating by= \n");

scanf("%f",&a);
scanf("%c", &op);
while(op!='=')
{
scanf("%f",&b);
switch(op)
{
case '+':
{
a=a+b;
break;
}
case '-':{
a=a-b;
break;
}
case '*':{
a=a*b;
break;
}
case '/':{
a=a/b;
break;
}
}//swtch
scanf("%c",&op);
}// while
printf("results is %f\n",a);
getch();
}
Example:
i/p: 3+4*5-6/2=
o/p: 14.5
Input/Output:
1)enter two operands:2 3 enter an operator:+
sum of two numbers 2 3 is: 5
2.)enter two operands:3 4 enter an operator: subtraction of two numbers 3 4 is: -1
24
3)enter two operands:3 5
enter an operator:*
product of two numbers 3 5 is: 15

4) enter two operands:5 2


enter an operator:/
quotient of two numbers 5 2 is: 2.5
5) enter two operands:5 2
enter an operator:%
reminder of two numbers 5 2 is: 1
conclusion: The program is error free
VIVA QUESTIONS:
1) What are the various types of arithemetic operators ?
Ans: addition (+), multiplication(*), subtraction (-), division(/) , modulo(%).
2) What are the types of relational operators ?
Ans: less than(<), grater than(>), less than or equal to(<=),equal to(==), etc..,
3) 3) What are the types of logical operators ?
Ans: logical AND (&&), logical OR(||), logical NOT(!)

You might also like