Calculator using switch case

C program for calculator using switch case :

code

 

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res,choice;
clrscr();
printf(“Choose one operation from following :\n”);
printf(“1.Addition\n2.Substraction\n3.Division\n4.Multiplication\n5.Reminder”);
printf(“\nChoose as you wish :”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
printf(“\nEnter first value :”);
scanf(“%d”,&a);
printf(“\nEnter second value :”);
scanf(“%d”,&b);
res=a+b;
printf(“\nAddition of given number is %d”,res);
break;
case 2:
printf(“\nEnter first value :”);
scanf(“%d”,&a);
printf(“\nEnter second value :”);
scanf(“%d”,&b);
res=a-b;
printf(“\nSubstraction of given number is %d”,res);
break;
case 3:
printf(“\nEnter first value :”);
scanf(“%d”,&a);
printf(“\nEnter second value :”);
scanf(“%d”,&b);
res=a/b;
printf(“\nDivision of given number is %d”,res);
break;
case 4:
printf(“\nEnter first value :”);
scanf(“%d”,&a);
printf(“\nEnter second value :”);
scanf(“%d”,&b);
res=a*b;
printf(“\nMultiplication of given number is %d”,res);
break;
case 5:
printf(“\nEnter first value :”);
scanf(“%d”,&a);
printf(“\nEnter second value :”);
scanf(“%d”,&b);
res=a%b;
printf(“\nReminder of given number is %d”,res);
break;
default :
printf(“\nChoice is not valid”);
}
getch();
}


output

Choose one operation from following :

1.Addition

2.Substraction

3.Division

4.Multiplication

5.Reminder

Choose as you wish :1

Enter first value :23

Enter second value :10

Addition of given number is 33

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s