Ad Code

Write a program to make a calculator using switch case statement.

Write a program to make a calculator using switch case statement.



#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, d;
clrscr();
printf(“enter the first number”);
scanf(“%d”,&a);
printf(“enter the second number”);
scanf(“%d”,&b);
printf(“choose option 1. Add\n 2. Subtract\n 3. Multiply\n 4. Divide\n ”);
scanf(“%d”,&d);
Switch(d)
{
Case 1:
{
c=a+b;
printf(“%d”,c);
break;
}
Case 2:
{
c=a-b;
printf(“%d”,c);
break;
}
Case 3: {
c=a*b;
printf(“%d”,c);
break;
}
Case 4:
{
c=a/b;
printf(“%d”,c);
break;
}
default:
{
printf(“invalid choice”);
break;
}
}
getch();
}

Post a Comment

0 Comments

Ad Code