Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that uses the switch statement to perform the correct operation

ID: 3532074 • Letter: W

Question

  1. Write a program that uses the switch statement to perform the correct operation (addition, subtraction, multiplication or division). The program prompts the user to enter an operator (+, or -, or *, or /) and two integers. Based on the type of operator, the program computes the result: either adds or subtracts, or multiplies, or divides the two numbers.
  1. Write a program that asks the user to enter five integers and the program finds and displays the largest number of them. To write the program, please review the attached file that shows you an example program to find the smallest number.

Explanation / Answer

1=# include < stdio.h >
# include < conio.h >
main ( )
{
int a,b,choice,result; /* Declare variables */
clrscr ( );
printf ( "1. Addition ");
printf ( " 2. Subtraction ");
printf ( " 3. Multiplication ");
printf ( " 4. Division ");
printf( " Enter values of a,b=");
scanf ( %d%d", &a, &b); / * Input numbers variables */
printf ( " Enter your choice :-" );
scanf ( "%d" ,&choice); / * Input choice variable */
switch ( choice) /* Select any one choice */
{
Case 1:
result=a+b;
printf( " Addition = %d " ,result);
break;
Case 2:
result=a-b;
printf( "Subtraction = %d " ,result);
break;
Case 3:
result=a*b;
printf( "Multiplication = %d " ,result);
break;
Case 4:
result=a/b;
printf( " Division = %d " ,result);
break;
default:
printf ( " Your choice is wrong ");
}
getch( );
}
Output:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter values of a,b= 8 4
Enter your choice :- 2
Subtraction =4

2=

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote