First and Last Digit
Practice this coding question on Coding Gurukul.
Problem statement
A warehouse uses a simple training checksum for decimal parcel identifiers. The checksum combines only the first and last decimal digits, ignoring the digits between them. It is intentionally lightweight so new staff can check it by hand before learning stronger verification schemes. Your program must generate this checksum for each identifier in a batch. Your task For every nonnegative integer n, find its first decimal digit and its last decimal digit, then print their sum. Decimal numbers are written without leading zeroes except for the number zero itself. Each identifier is processed independently. Important details For a one-digit number, that digit is both the first and the last, so it contributes twice. A number ending in zero has last digit zero. The checksum is not the sum of all digits. Worked example For identifier 5832, the first digit is 5 and the last is 2, giving checksum 7. For the single digit 8, the result is 16.
Input format
First line: T. Next T lines: n.
Output format
Print the sum of the first and last digit for each n.
Constraints
1 <= T <= 1000; 0 <= n <= 1000000000.
Sample input
2 5832 8
Sample output
7 16
Sign in to run or submit a solution in C++, Java or Python.