Switch case arithmetic operations program in c++

Que - Make a program for arthmetic operation by using switch case?

#include<iostream>
using namespace std;

int main()
{
    cout << "1.add\n";
    cout << "2.subtract\n";
    cout << "3.multiply\n";
    cout << "4.division\n";
   
    int a,b;
    int ch;
    cout<<"enter a number :- ";
    cin>>a;
    cout<<"enter a number :- ";
    cin>>b;
   
    cout<<"choose what operation is perform :- ";
    cin>>ch;
    switch(ch)
    {
    case 1:a=a+b;
    cout<<"sum of two numbers is :- "<<a;
    break;
    case 2:a=a-b;
    cout<<"subtract of two numbers is :- "<<a;
    break;
    case 3:a=a*b;
    cout<<"multiplication of two numbers is :- "<<a;
    break;
    case 4:a=a/b;
    cout<<"division of two numbers is :- "<<a;
    break;
    default : cout<<"invalid operation is perform";
    }
    return 0;
}

Result:-




Post a Comment

Previous Post Next Post