Showing posts with label First and Last Digit. Show all posts
Showing posts with label First and Last Digit. Show all posts

Sunday, 11 March 2018

First and Last Digit

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

  1. #include<stdio.h>
  2. int main()
  3. { int t,i,d;
  4. long a,w=0,c=0;
  5. scanf("%d",&t);
  6. while(t--)
  7. { long s=0;
  8. scanf("%ld",&a);
  9. w=a%10;
  10. while(a!=0){
  11. d=a%10;
  12. s=s*10+d;
  13. a=a/10;
  14. }
  15. c=s%10;
  16. printf("%ld\n",w+c);
  17. }
  18. }

 

Reverse The Number

Reverse The Number All submissions for this problem are available. If an Integer   N , write a program to reverse the given number. ...