switch program in c




It's similar to Fan Switch Light Switch

#include <stdio.h>

int main()
{
    int s;
    printf("\nEnter The Choice :");
    scanf(" %d", &s);
    switch(s){ (passed value of s here)
        case 1: (if the value of s is one the case one will be printed)
        printf("\n One ");
        break;
        case 2:
        printf("\n Two");
        break;
        case 3:
        printf("\n Three");
        break;
        default: (This is a keyword)
        printf("\nPls enter value From 1 to 3..");
        break;
    }

    return 0;
}

Switch is to activate the particular case.

If we take break it will printout with out checking.

Comments