Last Two Digits
Programming Basics · JavaScript
TASK
Problem
Given a non-negative integer, print the number formed by its last two digits.
EXAMPLE
Example
12345
45
LIMITS
Constraints
`n` is a non-negative integer. If `n` has only one digit, that digit is the result; otherwise use the last two decimal digits.
LEARN
Theory for this problem
+
### Last Two Digits
Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.
NEED HELP?
Hints
+
['Decide which part comes from division and which part comes from the remainder.', 'Match each input value type to the operation performed on it: JavaScript string and numeric behavior differ significantly.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let result = (((n) % (100)) + (100)) % (100);
console.log(result);