To test all arithmetic Operations Using Switch Statement (Second Method)

 Program:


#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b;
    char opt;
    clrscr();
    printf("Enter any Two Numbers : ");
    scanf("%d%d", &a, &b);
    printf("A-Addition\nS-Subtraction\nM-Multiplication\nD-Division\nR-Modulus\nEnter Your Option");
    fflush(stdin);
    scanf("%c", &opt);
    switch(opt)
    {
        case 'A':
        case 'a':
                printf("Addition of %d and %d is %d", a, b, a+b);
                break;
        case 'S':
        case 's':
                printf("Subtraction of %d and %d is %d", a, b, a-b);
                break;
        case 'M':
        case 'm':
                printf("Multiplication of %d and %d is %d", a, b, a*b);
                break;
        case 'D':
        case 'd':
                printf("Division of %d and %d is %d", a, b, a/b);
                break;
        case 'R':
        case 'r':
                printf("Modulus of %d and %d is %d", a, b, a%b);
                break;
        default:
                printf("Invalid Option");
    }
    getch();
}



Output:



Ex-1:
Enter any Two Numbers : 20    10

A-Addition
S-Subtraction
M-Multiplication
D-Division
R-Modulus
Enter Your Option : A (or) a

Addition of 20 and 10 is 30 

Ex-2:
Enter any Two Numbers : 20    10

A-Addition
S-Subtraction
M-Multiplication
D-Division
R-Modulus
Enter Your Option : S (or) s

Subtraction of 20 and 10 is 10

Ex-3:
Enter any Two Numbers : 20    10

A-Addition
S-Subtraction
M-Multiplication
D-Division
R-Modulus
Enter Your Option : M (or) m

Multiplication of 20 and 10 is 200

Ex-4:
Enter any Two Numbers : 20    10

A-Addition
S-Subtraction
M-Multiplication
D-Division
R-Modulus
Enter Your Option : D (or) d

Division of 20 and 10 is 2

Ex-5:
Enter any Two Numbers : 20    10

A-Addition
S-Subtraction
M-Multiplication
D-Division
R-Modulus
Enter Your Option : R (or) r

Modulus of 20 and 10 is 0


Next Topic        :  

Previous Topic :

No comments:

Post a Comment