What's up coders, today we will be solving First and Last Digit CodeChef Solution whose Problem code is FLOW004.
Problem
If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.
Input
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.
Output
For each test case, display the sum of first and last digits of N in a new line.
Constraints
- 1 <= T <= 1000
- 1 <= N <= 1000000
Example
Input:
3 1234 124894 242323
Output:
5 5 5
Solution - First and Last Digit - CodeChef Solution
Python 3
#Solution Provided by Sloth Coders T = int(input()) while T > 0: n = (input()) reverse = n[::-1] reverse = int(reverse) n = int(n) first_digit = reverse % 10 last_digit = n % 10 sum = first_digit + last_digit print(sum) T = T - 1
Disclaimer: The above Problem (First and Last Digit) is generated by CodeChef but the Solution is provided by Sloth Coders.
Happy Coding !!
A Sloth Who loves to Code
Also Read: