Pages

/*
Q. WAP using switch-case to provide the options for the addition, subtraction, multiplication and division of two user given integer numbers.                
    1. Addition
    2. Subtraction
    3. Multiplication
    4. Division
    If user reads any other choice then a message “Invalid Choice” should be displayed on the monitor.
*/


#include<stdio.h>

main()
{
    int a,b,choice;
    printf("\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division");
    printf("\nEnter your choice=");
    scnaf("%d",&choice);
    printf("\nEnter two numbers=");
    scnaf("%d%d",&a,&b);
    switch(choice)
    {
        case 1:
            printf("\nAddition of %d and %d is %d",a,b,a+b);
            break;
        case 2:
            printf("\nSubtraction of %d and %d is %d",a,b,a-b);
            break;
        case 3:
            printf("\nMultiplication of %d and %d is %d",a,b,a*b);
            break;           
        case 4:
            printf("\nDivision of %d and %d is %d",a,b,a/b);
            break;
        default:
            printf("\nInvalid choice");           
    }

}

No comments:

Post a Comment