Â
In this, we are going to see a program in which will be a menu driven program to perform arithmetic operations in C Programming Language.
//Write a menu driven program to perform arithmetic operations
#include <stdio.h>
void main()
{
int n, num1, num2;
float result;
printf("Enter the two numbers: ");
scanf("%d %d", &num1, &num2);
printf("****SELECT THE OPERATION*****\n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\n");
printf("Enter the corresponding number of operation: ");
scanf("%d", &n);
switch (n)
{
case 1:
result = num1 + num2;
printf("The Addition of %d and %d = %f", num1, num2, result);
break;
case 2:
result = num1 - num2;
printf("The Subtraction of %d and %d = %f", num1, num2, result);
break;
case 3:
result = num1 * num2;
printf("The Multiplication of %d and %d = %f", num1, num2, result);
break;
case 4:
result = (float)num1 / (float)num2;
printf("The Division of %d and %d = %f", num1, num2, result);
break;
case 5:
result = num1 % num2;
printf("The Remainder after division of %d and %d = %f", num1, num2, result);
break;
default:
printf("Invalid Entry");
break;
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP