Float Variable in C

Level 243 keystrokes

Stores 3.14 in a float variable and prints it rounded to 2 decimal places with %.2f: "Pi: 3.14".

C code

// float stores numbers with a fractional part; the f suffix makes 3.14f a float literal
1float pi = 3.14f;
// %.2f prints the value rounded to 2 decimal places: "Pi: 3.14"
2printf("Pi: %.2f\n", pi);

Output

Pi: 3.14
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
  • "× 2
  • ,× 1
  • :× 1
  • (× 1
  • )× 1
  • \× 1
  • %× 1
  • =× 1

More C examples at level 2

← C typing practice