Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.
For each test case, display the sum of first and last digits of N in a new line.
Input: 3
1234
124894
242323
Output: 5
5
5
for i in range(int(input())):
s = input()
print(int(s[0]) + int(s[len(s) - 1]))
#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;
}
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));
}
}
}
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
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 >>