Wednesday, February 11, 2015

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<<"

1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Mode";

cout<<"
 Enter your choice:";

cin>>ch;

switch(ch)
{
case 1:
{
cout<<"

Enter two variables:";

cin>>a>>b;
res=a+b;
cout<<"
 Result="<<res;

}
break;

case 2:
{
cout<<"

Enter two variables:";

cin>>a>>b;
res=a-b;
cout<<"
 Result="<<res;

}
break;

case 3:
{
cout<<"

Enter two variables:";

cin>>a>>b;
res=a*b;
cout<<"
 Result="<<res;

}
break;

case 4:
{
cout<<"

Enter two variables:";

cin>>a>>b;
if(a>=b)
{
res=a/b;
cout<<"
 Result="<<res;

}
else
cout<<"

1st varable should be greater than 2nd.!!!";

}
break;

case 5:
{
cout<<"

Enter two variables:";

cin>>a>>b;
if(a>=b)
{
q=a/b;
res=a-(b*q);
cout<<"
 Result="<<res;

}
else
cout<<"

1st variable should be greater than 2nd..!!!";

}
break;
}

getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.