304 North Cardinal St.
Dorchester Center, MA 02124

# First and Last Digit CodeChef Solution

## Problem – First and Last Digit CodeChef Solution

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.

•  T  1000
•  N  1000000

### Example

``````Input: 3
1234
124894
242323
Output: 5
5
5``````

### First and Last Digit CodeChef Solution in Pyth 3

``````for i in range(int(input())):
s = input()
print(int(s) + int(s[len(s) - 1]))

``````

### First and Last Digit CodeChef Solution in C++14

``````#include <iostream>
using namespace std;
typedef long long ll;

int main() {
ll t;
cin>>t;
while(t--)
{
ll n,last,first;
cin>>n;
last=n%10;
while(n>=10)
{
n=n/10;
}
first=n;
cout<<last+first<<"\n";

}
return 0;
}``````

### First and Last Digit CodeChef Solution in Java

``````import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static int sum(int n){
int l=n%10, f=0;
while(n>0){
f=n%10;
n=n/10;
}
return l+f;
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner get = new Scanner(System.in);
int t=get.nextInt();
for(int i=0; i<t; i++){
int n=get.nextInt();
System.out.println(sum(n));
}
}
}

``````
##### First and Last Digit CodeChef Solution Review:

In our experience, we suggest you solve this First and Last Digit CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the First and Last Digit CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this First and Last Digit CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions