Showing posts with label case. Show all posts
Showing posts with label case. Show all posts
Wednesday, February 18, 2015
C program to perform arithmetic operations using switch case

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int ch;
float a,b,res;
clrscr();
printf("Enter two numbers:");
scanf("%f%f",&a,&b);
printf("
Menu
1.Addition
2.Subtraction
3.Multiplication
4.Division");
printf("
Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: res=a+b;
break;
case 2: res=a-b;
break;
case 3: res=a*b;
break;
case 4: res=a/b;
break;
default: printf("Wrong choice!!
Press any key...");
getch();
exit(0);
}
printf("
Result=%f",res);
getch();
}
Labels:
arithmetic,
c,
case,
operations,
perform,
program,
switch,
to,
using
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();
}
#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();
}
Labels:
all,
arithmetic,
c,
calculation,
case,
perform,
program,
switch,
to,
using
Subscribe to:
Posts (Atom)