0
6.6kviews
Write a menu driven program to perform arithmetic operations on two integers the menu should be repeated until the user selects STOP option.

Program should have independent user defined function for each case.

1 Answer
0
127views

Program:

#include<stdio.h>

#include<conio.h>

void main()

{

    int operator,ans;

    double firstNumber,secondNumber;

    clrscr();

    do

    {

        printf("Enter aoperation:\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
Please log in to add an answer.