Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link

First and Last Digit : FLOW004 | CodeChef Solution

1 min read


Problem

If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.

Input Format

  • The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.

Output Format

For each test case, display the sum of first and last digits of N in a new line.

Constraints

  •  T  1000
  •  N  1000000
  • 1 \leq T \leq 

Sample 1:

Input
3
1234
124894
242323

Output
5
5
5

Solution

#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;
}
Please First Try to Solve Problem by Yourself.

You may like these posts

  • ProblemWrite a program to obtain length (L)(L) and breadth (B)(B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.Input FormatFirst l…
  • ProblemAlice and Bob are meeting after a long time. As usual they love to play some math games. This times Alice takes the call and decides the game. The game is very simple, Alice…
  • ProblemYou and your friend are playing a game with hoops. There are NN hoops (where NN is odd) in a row. You jump into hoop 11, and your friend jumps into hoop NN. Then you jump in…
  • ProblemGru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him aw…
  • ProblemChef is a big fan of Coldplay. Every Sunday, he will drive to a park taking MM minutes to reach there, and during the ride he will play a single song on a loop. Today, he ha…
  •  ProblemIn a coding contest, there are prizes for the top rankers. The prize scheme is as follows:Top 10 participants receive rupees X each.Participants with rank 11 to 100 (b…

Post a Comment