Monday, 5 October 2015

Add, subtract and multiply two nos. using switch statement.

  
   
#include<stdio.h>
//#include<conio.h>
void main() {
    int ch, a, b, c;
    //clrscr();
    printf("enter a:");
    scanf("%d", &a);
    printf("enter b:");
    scanf("%d", &b);
    printf("----------MENU-----------\n");
    printf("1.addition\n");
    printf("2.subtraction\n");
    printf("3.multiplication\n");
    scanf("%d", &ch);
    switch (ch) {
        case 1:
            c = a + b;
            printf("addition of a and b=%d", c);
            break;
        case 2:
            c = a - b;
            printf("subtraction of a and b=%d", c);
            break;
        case 3:
            c = a*b;
            printf("Multiply of a and b=%d", c);
            break;
        default:
            printf("wrong choice");
    }
    //getch();
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

No comments:

Post a Comment