C++ Program to perform all arithmetic calculation using switch case

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

void main()
{
clrscr();
float a,b,res;
int ch,q;
cout<<“Arithmetic Operatios”;
cout<<“nn1.Additionn2.Subtractionn3.Multiplicationn4.Divisionn5.Mode”;
cout<<“n  Enter your choice:”;
cin>>ch;

switch(ch)
{
case 1:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a+b;
cout<<“n  Result=”<<res;
}
break;

case 2:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a-b;
cout<<“n  Result=”<<res;
}
break;

case 3:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a*b;
cout<<“n  Result=”<<res;
}
break;

case 4:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
if(a>=b)
{
res=a/b;
cout<<“n  Result=”<<res;
}
else
cout<<“nnt1st varable should be greater than 2nd.!!!”;
}
break;

case 5:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
if(a>=b)
{
q=a/b;
res=a-(b*q);
cout<<“n  Result=”<<res;
}
else
cout<<“nnt1st variable should be greater than 2nd..!!!”;
}
break;
}

getch();
}

3 thoughts on “C++ Program to perform all arithmetic calculation using switch case

    1. seemi

      in simple c language prog to make a looped triangle

      #include
      main()
      {
      int i , j ;
      for (i = 1 ; i < = 5 ; i ++)
      {
      for ( j = 1 ; j < = i ; j ++)
      {
      printf ("%d " , j);
      }
      printf ("\n");
      }
      }

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *