Reverse Number in C
Level 3101 keystrokes
Reverses the digits of an integer using modulo and division.
C code
// Reverse 1234; rev builds the reversed number, starting at 01int num = 1234, rev = 0;// One pass per digit of num2while (num > 0) { // num % 10 is the last digit; rev * 10 makes room for it: 4, 43, 432, 43213 rev = rev * 10 + num % 10; // Drop the digit that was just used4 num /= 10;5}// Print 43216printf("%d", rev);Output
4321
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=× 4,× 2"× 2(× 2)× 2%× 2{× 1}× 1*× 1