Advertisement
RicardasSim

switch range

Jan 18th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. //warning: range expressions in switch statements are non-standard [-Wpedantic]
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char* argv[]) {
  7.  
  8.     int x = 5;
  9.    
  10.     switch (x){
  11.  
  12.         case 1 ... 10:
  13.             printf ("x: %d is in between 1-10\n",x);
  14.         break;
  15.         default:
  16.             printf ("x: %d is not in between 1-10\n",x);  
  17.     }
  18.  
  19.  
  20.     switch (x){
  21.  
  22.         case 1:
  23.         case 2:
  24.         case 3:
  25.         case 4:
  26.         case 5:
  27.             printf ("x: %d is in between 1-5\n",x);
  28.         break;
  29.         default:
  30.             printf ("x: %d is not in between 1-5\n",x);
  31.     }
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement