First and Last Digit Solution

 First and Last Digit Solution

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:

1234

Output:

5


Program:
#include <stdio.h>
#include<math.h>
int main()
{
    int n,len=0;
    scanf("%d",&n);
    int temp=n;
    while(temp/=10)
    {
          len++;
    }
    int last_digit = n%10;
    int first_digit = n/pow(10,len);
    int sum=last_digit+first_digit;
    printf("%d",sum);
    return 0;
}

Post a Comment

0 Comments