मराठी

Write a Menu Driven Program to Perform Arithmetic Operations on Two Integers. the Menu Should Be Repeated Until User Selects “Stop” Option. Program Should Have Independent User Defined Functions

Advertisements

प्रश्न

Write a menu driven program to perform arithmetic operations on two integers. The menu should be repeated until user selects “STOP” option. Program should have independent user defined functions for each case.

थोडक्यात उत्तर
Advertisements

उत्तर

#include<stdio.h>
#include<conio.h>
void main()
{
int operator,ans;
double firstNumber,secondNumber;
clrscr();
do
{
printf("Enter a operation:\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Divison");
scanf("%d", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&firstNumber, &secondNumber);
switch(operator)
{
case 1:
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber);
break;
case 2:
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
break;
case 3:
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
break;
case 4:
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
break;
default:
printf("Error! operator is not correct");
}
printf("\nDo you want to continue 1.YES 2. NO");
scanf("%d",&ans);
}
while(ans==1);
getch();
}

Output:
Enter an Operation:
1. Addition
2. Subtraction
3. Multiplication
4. Division
       1
       Enter two operands 10 20
       10.0 + 20.0 = 30.0
       Do you want to continue 1.YES 2.NO 1
       Enter an operation
       1. Addition
       2. Subtraction
       3. Multiplication
       4. Division
       2
       Enter two operands: 50 60
       50.0 – 60.0 = -10.0
       Do you want to continue 1.YES 2.NO 2

shaalaa.com
Operators in C-Programming
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2016-2017 (June) CBCGS

APPEARS IN

Advertisements
Share
Notifications



      Forgot password?
Course
Use app×