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
Sample 1:
Input
Output
3
1234
124894
242323
5
5
5
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int rem = n%10;
while(n>9)
{
n = n/10;
}
cout<<n+rem<<endl;
}
return 0;
}
Comments
Post a Comment