First and Last Digit ( codechef Problem code: FLOW004)

PROBLEM :

All submissions for this problem are available.

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

Input

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

Output

Display the sum of first and last digit of N.

Constraints

1 = T = 1000
1 = N = 1000000
Example

Input
3
1234
124894
242323

Output
5
5
5
   
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std ;
int sum_end_start(int ) ;
int main()
{
int t,no,sum ;
cin>>t ;
while(t--)
{
cin>>no ;
sum=sum_end_start(no) ;
cout<<sum<<endl ;
}
}

int sum_end_start(int no)
{
int i,r,sum=0 ;
i=no ;
while(no!=0)
{
r=no%10 ;
if((no==i)||(no/10==0))
sum=sum+r ;
no=no/10 ;
}
return sum ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )