24: W.A.P.
to make simple calculator using Switch Case.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int num1, num2, choice;
printf("Enter 1st and 2nd number =
");
scanf("%d %d", &num1,
&num2);
printf("\n1. Addition\n2. Subtract\n3.
Multiplication\n4. Division\n5. Modulus\nEnter the choice = ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\n%d + %d =
%d", num1, num2, num1 + num2);
break;
case 2:
printf("\n%d - %d =
%d", num1, num2, num1 - num2);
break;
case 3:
printf("\n%d * %d =
%d", num1, num2, num1 * num2);
break;
case 4:
printf("\n%d / %d =
%d", num1, num2, num1 / num2);
break;
case 5:
printf("\n%d %% %d =
%d", num1, num2, num1 % num2);
break;
default:
printf("\nWrong
Choice!");
}
getch();
}
Please follow me for more practicals....
Output:
Enter 1st and 2nd
number = 3 4
1. Addition
2. Subtract
3. Multiplication
4. Division
5. Modulus
Enter the choice = 3
3 * 4 = 12
Algorithm:
1.
START
2.
Declare
num1, num2 and choice.
3.
Enter the
num1 and num2.
4.
Display
List of choice.
5.
Enter the
choice.
6.
If
(choice == 1) then goto step 7 else goto step 8.
7.
Display
num1 + num2.
8.
If
(choice == 2) then goto step 9 else goto step 10.
9.
Display
num1 – num2.
10. If (choice == 3) then goto step 12 else goto
step 13.
11. Display num1 * num2.
12. If (choice == 4) then goto step 14 else goto
step 15.
13. Display num1 / num2.
14. If (choice == 5) then goto step 15 else goto
step 16.
15. Display num1 % num2.
16. STOP.
Please follow me for more practicals....
Flowchart: