//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
#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(!)
program
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
#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(!)
program
No comments:
Post a Comment