First and Last Digit||codechef||beginner solution ||programming info

First and Last Digit

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

  •  T  1000
  •  N  1000000

Example

Input
3 
1234
124894
242323

Output
5
5
5
SOLUTION USING C LANGUAGE:-
#include <stdio.h>
int main(void) {
    int t,i,n,r,s;
    scanf("%d\n",&t);
    for(i=0;i<t;i++){
        scanf("%d\n",&n);
        r=n%10;
        while(n>9)
        {
            n=n/10;
        }
        s=n+r;
        printf("%d\n",s);
    }
	// your code goes here
	return 0;
}

Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support