Tuesday, 29 March 2016

Program to print different calculations using switch case condition in c++ language.

//WAP to print different calculations using switch case.
 

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();

int a,b,d;
char ch;
cout<<"enter the values of a and b";
cin>>a>>b;
cout<<"enter the operator or case";
cin>>ch;
switch(ch)
{
case '+':
d=a+b;
cout<<"sum of a and b is:"<<" "<<d<<endl;
break;
case '*':
d=a*b;
cout<<"multiplication of a and b is:"<<" "<<d<<endl;
break;
case '-':
d=a-b;
cout<<"subtraction of a and b is:"<<" "<<d<<endl;
break;
case '/':
d=a/b;
cout<<"division of a and bis:"<<" "<<d<<endl;
break;
default:
cout<<"wrong case no calculations:"<<endl;
break;
}
getch();
}


Output:-
                                         

No comments:

Post a Comment