Write a
program, which takes two integer operands &
one operator form user, performs the operation & then print the result. (Consider the
operators +, - , / , % and use switch statement). For example, the
input should be in the form: 5 + 3 the output should comes Result = 8
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
char op;
cout<<"enter the number a and b";
cin>>a>>b;
cout<<"enter operator (+, -, *, /, %)";
cin>>op;
switch (op)
{
case('+'):
c=a+b;
cout<<"addition is"<<c;
break;
case('-'):
c=a-b;
cout<<"subtraction is"<<c;
break;
case('*'):
c=a*b;
cout<<"multiplication is"<<c;
break;
default:
cout<<"wrong opperator";
}//switch
getch();
}//main
No comments:
Post a Comment