Write a program in C which is a Menu-Driven Program to perform a simple calculation

 


#include <stdio.h>

#include <conio.h>

void main()

{

    int abcans;

    printf("[1] additon\n");

    printf("[2] Subtraction\n");

    printf("[3] multiplication\n");

    printf("[4] division\n");

    printf("[5] exit\n");

    printf("Select a option from above: ");

    scanf("%d", &a);

    switch (a)

    {

    case 1:

        printf("enter a first number: ");

        scanf("%d", &b);

        printf("enter a second number: ");

        scanf("%d", &c);

        ans = b + c;

        printf("Addition of %d and %d is %d"bcans);

        break;

    case 2:

        printf("enter a first number: ");

        scanf("%d", &b);

        printf("enter a second number: ");

        scanf("%d", &c);

        ans = b - c;

        printf("Subtraction of %d and %d is %d"bcans);

        break;

    case 3:

        printf("enter a first number: ");

        scanf("%d", &b);

        printf("enter a second number: ");

        scanf("%d", &c);

        ans = b * c;

        printf("%d Multiply with %d is %d"bcans);

        break;

    case 4:

        printf("enter a first number: ");

        scanf("%d", &b);

        printf("enter a second number: ");

        scanf("%d", &c);

        ans = b / c;

        printf("Divisiton of %d and %d is %d"bcans);

        break;

    case 5:

        break;

    default:

        printf("sorry! your requirement is not here. \nSoon we will update you.");

        break;
    }
}

OUTPUT
[1] addition
[2] Subtraction
[3] multiplication
[4] division
[5] exit
Select an option from above: 3
enter a first number: 7
enter a second number: 8
7 Multiply with 8 is 56

[1] addition
[2] Subtraction
[3] multiplication
[4] division
[5] exit
Select an option from above: 5

Follow our page for regular updates.

0 Comments