Wednesday 27 September 2017

"First and the Last Digit"- PROGRAM IN C

First and the Last Digit


If Given an integer N. Write a program to obtain the sum of the first and last digit of this number.


Input

The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an integer N.


Output

Display the sum of first and last digit of N.

Constraints

1<= T <= 100
1<= N <=1000000


Example

Input
3
1234
124894
242323

Output
5
5
5


Solution:

#include<stdio.h>
int main()
{
    int t,a,b;
    unsigned long int n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lu",&n);
        a=n%10;
        while(n>=10)
        {
            n=n/10;
        }
        b=n%10;
        printf("%d\n",a+b);
    }


    return 0;
}

No comments:

Post a Comment