# First and Last Digit: FLOW004

Codechef submission link: Click

Submission link for CU: CLICK HERE

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

**Answer: ** Please login to see answer.

## First and Last Digit Codechef solution in C++

```
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int rem = n%10;
while(n>9)
{
n = n/10;
}
cout<< n+rem<< el;
}
return 0;
}
```

## First and Last Digit Codechef solution in Python

```
# We have populated the solutions for the 10 easiest problems for your support.
# Click on the SUBMIT button to make a submission to this problem.
#Note that it's python3 Code. Here, we are using input() instead of raw_input().
#You can check on your local machine the version of python by typing "python --version" in the terminal.
for i in range(int(input())):
s = input()
print(int(s[0]) + int(s[len(s) - 1]))
```

## First and Last Digit Codechef solution in Java

```
// We have populated the solutions for the 10 easiest problems for your support.
// Click on the SUBMIT button to make a submission to this problem.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner get = new Scanner(System.in);
int i=0,sum=0,rem=0,t = get.nextInt();
while(i<t)
{
int a = get.nextInt();
sum = a%10;
while(a>0)
{
rem = a%10;
a = a/10;
}
sum = sum+rem;
System.out.println(sum);
i++;
}
}
}
```

First and Last Digit Codechef solution by

The content uploaded on this website is for reference purposes only. Please do it yourself first. |