Switch Statement in C - Switch Case Statement using Range in C Program



 Switch Case Statement using Range in C Program

Learn c - c tutorial - Switch Case Statement using Range in C Program - c examples - c programs

Switch Case Statement using Range in C Program

  • Switch case statements are compare a variable to several integral values and the multi method branch statement.
  • It provides a simple way to dispatch execution to different components of code based on the value of the expression and Switch is a control statement that allows a value to change control of execution.
 Switch Case Statement using Range in C Program

Learn c - c tutorial - Switch Case Statement using Range in C Program - c examples - c programs

Sample Code

#include <stdio.h>
int main()
{
    int num=57;
    printf("Given number (1-100): %d\n",num);
    switch(num) {
    case 1 ... 50:
        printf("Number is in between 1 to 50\n");
        break;
    case 51 ... 100:
        printf("Number is in between 51 to 100\n");
        break;
    default:
        printf("Number is out of range!!!\n");
        break;
    }
    return 0;
}

Output

Given number (1-100): 57
Number is in between 51 to 100


View More Quick Examples


Related Searches to Switch Statement in C - Switch Case Statement using Range in C Program