Switch with int case : Switch « Language Basics « C / ANSI-C






Switch with int case

  
#include <stdio.h>

int main(void)
{
  int i;

  printf("Enter a number between 1 and 4: ");
  scanf("%d", &i);

  switch(i) {
    case 1:
      printf("one");
      break;
    case 2:
      printf("two");
      break;
    case 3:
      printf("three");
      break;
    case 4:
      printf("four");
      break;
    default:
      printf("Unrecognized Number");
  }

  return 0;
}

           
       








Related examples in the same category

1.a simple 4 function calculator
2.Switch demo
3.How to use switch: number
4.How to use switch: char
5.Switch: char and nested if
6.Switch inside for loop
7.Switch with char case
8.Get three input at the same time: scanf
9.Console menu: switch with char case
10.Switch with default