Problem
If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.
Input Format
- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.
Output Format
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
Sample 1:
Input
3
1234
124894
242323Output
5
5
5
Solution
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll t;
cin>>t;
while(t--)
{
ll n,last,first;
cin>>n;
last=n%10;
while(n>=10)
{
n=n/10;
}
first=n;
cout<<last+first<<"\n";
}
return 0;
}
Please First Try to Solve Problem by Yourself.