PROBLEM 9
Easy

Sum of Digits of a Two-Digit Number

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#9

Given a positive two-digit integer `n`, print the sum of its digits.

EXAMPLE

Example

Input
47
Output
11

LIMITS

Constraints

10 ≤ n ≤ 99
📖
LEARN Theory for this problem
+

### Sum of Digits of a Two-Digit Number

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.', 'Verify the accumulator initial value and both loop boundaries; this is where off-by-one errors most often appear.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let result = (Math.floor((n) / (10)) + (((n) % (10)) + (10)) % (10));
console.log(result);