Program:-
#include<iostream>
using namespace std;
int main()
{
int a,b,ch,ans;
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
cout<<"1.Addition \n2.Subtraction \n3.Multiplication \n4.Division \n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1: ans=a+b;
break;
case 2: ans=a-b;
break;
case 3: ans=a*b;
break;
case 4: ans=a/b;
break;
default: cout<<"Invalid choice!";
}
cout<<"Answer is:"<<ans<<endl;
}
Output:-
#include<iostream>
using namespace std;
int main()
{
int a,b,ch,ans;
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
cout<<"1.Addition \n2.Subtraction \n3.Multiplication \n4.Division \n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1: ans=a+b;
break;
case 2: ans=a-b;
break;
case 3: ans=a*b;
break;
case 4: ans=a/b;
break;
default: cout<<"Invalid choice!";
}
cout<<"Answer is:"<<ans<<endl;
}
Output:-
No comments:
Post a Comment