First and Last Digit
All submissions for this problem are available.
If Give 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 ≤ 1000
- 1 ≤ N ≤ 1000000
Example
Input 3 1234 124894 242323 Output 5 5 5
Solution
- #include<stdio.h>
- int main()
- { int t,i,d;
- long a,w=0,c=0;
- scanf("%d",&t);
- while(t--)
- { long s=0;
- scanf("%ld",&a);
- w=a%10;
- while(a!=0){
- d=a%10;
- s=s*10+d;
- a=a/10;
- }
- c=s%10;
- printf("%ld\n",w+c);
- }
- }
No comments:
Post a Comment