Search This Blog

Loading...

Explain the syntax of switch…case statement. Write a program using switch…case statement. : GTU Nov-Dec 2010

#include<stdio.h>
#include<conio.h>

void main()
{
    int no1,no2,choice;
    clrscr();
    printf("\n Please enter Number 1 : ");
    scanf("%d",&no1);
    printf("\n Please enter Number 2 : ");
    scanf("%d",&b);
    printf("Enter Choice : ");
    printf("\n1. Add");
    printf("\n2. Subtract");
    printf("\n3. Multiply");
    printf("\n4. Divide\n\n\t : ");
    scanf("%d",&choice);
 
    switch(choice)
    {
        case 1 :
            printf("Addition : %d",no1+no2);
            break;
        case 2 :
            printf("Subtraction : %d",no1-no2);
            break;
        case 3 :
            printf("Multiplication : %d",no1*no2);
            break;
        case 4 :
            printf("Divided : %d",no1/no2);
            break;
        default :
            printf("Your Choice is Wrong");
            break;
    }
    getch();
}

No comments:

Post a Comment