У нас вы можете посмотреть бесплатно PPS Ex: 9 Menu driven program in C using switch-case statements to perform arithmetic operations или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
PPS Experiment 9 : Implement a menu-driven program in C using switch-case statements to perform arithmetic operations | DBATU | PPS |
Subject : Programming for Problem Solving Lab (24AF1000ES107L )
Experiment 9 : Implement a menu-driven program in C using switch-case statements to perform arithmetic operations
Menu Display:
------------
The program displays a menu of arithmetic operations and an exit option.
User Input: The user inputs their choice and the numbers for the operation.
Switch-Case: Each case corresponds to an arithmetic operation or the exit option.
If the user enters an invalid choice, the default case handles it.
Loop: The menu is displayed repeatedly using a while (1) loop until the user chooses to exit.
Sample Output:
Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 1
Enter two numbers: 5 7
Result: 12.00
This program is simple, interactive, and demonstrates the use of switch-case and while/do_while statements effectively.
//Exp 9 : Menu driven C program to perform arithmetic operations
#include stdio.h
#include conio.h
int main() {
int choice;
double num1, num2, result;
while (1) {
// Display menu
printf("
Menu:
");
printf("Enter 1. Addition
");
printf("Enter 2. Subtraction
");
printf("Enter 3. Multiplication
");
printf("Enter 4. Division
");
printf("Enter 5. to Exit the program
");
printf("Enter your choice (1-5): ");
scanf("%d", &choice);
// Perform the chosen operation
switch (choice) {
case 1: // Addition
printf("Enter two numbers to perform addition : ");
scanf("%lf %lf", &num1, &num2);
result = num1 + num2;
printf("Addition Result: %.2lf
", result);
break;
case 2: // Subtraction
printf("Enter two numbers to perform substraction: ");
scanf("%lf %lf", &num1, &num2);
result = num1 - num2;
printf("Substraction Result: %.2lf
", result);
break;
case 3: // Multiplication
printf("Enter two numbers to perform Multiplication : ");
scanf("%lf %lf", &num1, &num2);
result = num1 * num2;
printf("Multiplication Result: %.2lf
", result);
break;
case 4: // Division
printf("Enter two numbers to perform Division operation: ");
scanf("%lf %lf", &num1, &num2);
if (num2 != 0) {
result = num1 / num2;
printf("Division Result: %.2lf
", result);
} else {
printf("Error: Division by zero is not allowed.
");
}
break;
case 5: // Exit
printf("Exiting the program. Goodbye!
");
return 0;
default: // Invalid choice
printf("Invalid choice! Please try again.
");
}
}
getch();
return 0;
}
Output: