Arithmetic Operations in C

Level 274 keystrokes

Divides 17 by 5 with integers: / gives the quotient 3 (the fraction is dropped) and % gives the remainder 2. It prints "Div: 3" and "Mod: 2".

C code

// Declares two ints in one statement: a = 17 and b = 5
1int a = 17, b = 5;
// Dividing two ints drops the fraction: 17 / 5 is 3, so this prints "Div: 3"
2printf("Div: %d\n", a / b);
// % gives the remainder: 17 = 5 * 3 + 2, so this prints "Mod: 2"
3printf("Mod: %d\n", a % b);

Output

Div: 3
Mod: 2
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.

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

More C examples at level 2

← C typing practice