0% found this document useful (0 votes)
14 views2 pages

Out Put Code

The document contains a C program for a simple calculator that performs addition, subtraction, multiplication, and division. It displays a menu for the user to choose an operation, takes two numbers as input, and displays the result. The program continues to run until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Out Put Code

The document contains a C program for a simple calculator that performs addition, subtraction, multiplication, and division. It displays a menu for the user to choose an operation, takes two numbers as input, and displays the result. The program continues to run until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>

void showMenu() {
printf("Simple Calculator\n");
printf("=================\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Exit\n");
printf("Choose an operation: ");
}

int main() {
int choice;
double num1, num2, result;

while (1) {
showMenu();
scanf("%d", &choice);

if (choice == 5) {
printf("Exiting...\n");
break;
}

printf("Enter first number: ");


scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);

switch (choice) {
case 1:
result = num1 + num2;
printf("Result: %lf\n", result);
break;
case 2:
result = num1 - num2;
printf("Result: %lf\n", result);
break;
case 3:
result = num1 * num2;
printf("Result: %lf\n", result);
break;
case 4:
if (num2 != 0) {
result = num1 / num2;
printf("Result: %lf\n", result);
} else {
printf("Error: Division by zero is not allowed.\n");
}
break;
default:
printf("Invalid choice. Please try again.\n");
break;
}
printf("\n");
}
return 0;
}

You might also like