Given a non-negative integer n with at least two digits, compute and return the sum of the last two digits
Example:
Input: n = 2379 Output: 16 Explanation: Last two digits of n are 7 and 9, so our answer is 7 + 9 = 16
Hints:
You can make use of modulo operator
You can get the last digit of a number using modulo 10:
2379 % 10 = 9
You can get a number consisting of last 2 digits using modulo 100:
2379 % 100 = 79
If you have a 2 digit number, you can get the first digit by using integral division
Divide a 2 digit number to 10 to get the first digit:
79 / 10 = 7
You can make use of modulo operator
You can get the last digit of a number using modulo 10:
2379 % 10 = 9
You can get a number consisting of last 2 digits using modulo 100:
2379 % 100 = 79
If you have a 2 digit number, you can get the first digit by using integral division
Divide a 2 digit number to 10 to get the first digit:
79 / 10 = 7
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check