Name:-Pavan Kalaskar Roll No: - 2026
Name:-Pavan Kalaskar Roll No: - 2026
Roll No :- 2026
#include <stdio.h>
Int main() {
Char opt;
// Perform the operation based on user input and display the result
Switch (opt) {
Case ‘+’:
Break;
Case ‘-‘:
Break;
Case ‘*’:
Break;
Case ‘/’:
} else {
Break;
Default:
}
Output :-
Code Explanation:-
This C program functions as a simple calculator. It begins by declaring
variables to store two numbers (`num1` and `num2`) and the result of an
operation. The user is prompted to input two numbers, then asked to choose
an arithmetic operator (`+`, `-`, `*`, `/`). The program uses a `switch`
statement to determine the operation to perform based on the user’s choice.
For division, it checks if the divisor (`num2`) is zero to prevent division by
zero errors. The result is displayed with two decimal places. If the user
inputs an invalid operator, an error message is shown.