Day Switch in C

Level 3145 keystrokes

Uses switch statement to print day name based on integer value.

C code

// 3 stands for Wednesday
1int day = 3;
// Jump straight to the case whose label equals day
2switch (day) {
// Each case ends with break so that only one name is printed
3 case 1: printf("Mon"); break;
4 case 2: printf("Tue"); break;
// This case matches and prints Wed
5 case 3: printf("Wed"); break;
// Used for any other value; as the last label it needs no break
6 default: printf("Other");
7}

Output

Wed
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • ;× 8
  • "× 8
  • (× 5
  • )× 5
  • :× 4
  • {× 1
  • }× 1
  • =× 1

More C examples at level 3

← C typing practice