Zero Padding in C

Level 244 keystrokes

Uses the format %05d to print 42 padded with leading zeros to 5 digits: "Number: 00042".

C code

// The number to format is 42
1int num = 42;
// In %05d, 5 is the width and 0 pads with zeros instead of spaces: "00042"
2printf("Number: %05d\n", num);

Output

Number: 00042
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.

  • ;× 2
  • "× 2
  • ,× 1
  • :× 1
  • (× 1
  • )× 1
  • \× 1
  • %× 1
  • =× 1

More C examples at level 2

← C typing practice