If-Else Statement in C

Level 3123 keystrokes

Uses if-else statement to check if a number is positive, negative, or zero.

C code

// The value to classify
1int num = 15;
// First test: 15 > 0 is true, so this branch runs
2if (num > 0) {
3 printf("Positive\n");
// Checked only when the first test fails
4} else if (num < 0) {
5 printf("Negative\n");
// Neither test matched, so num must be 0
6} else {
7 printf("Zero\n");
8}

Output

Positive
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.

  • "× 6
  • (× 5
  • )× 5
  • ;× 4
  • {× 3
  • }× 3
  • \× 3
  • <× 1
  • =× 1
  • >× 1

More C examples at level 3

← C typing practice