Algorithm


 problem Link :  https://www.codechef.com/problems/FLOW00

Problem

Given 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

  • 1≤�≤1000
  • 1≤�≤1000000

Sample 1:

Input
 
Output
 
3 
1234
124894
242323
5
5
5

Code Examples

#1 Code Example with C Programming

Code - C Programming

 #include<stdio.h>
int main()
{
    int n,num,first,last;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&num);
        last=num%10;
        while(num>0)
        {
            first=num%10;
            num=num/10;
        }
        printf("%d\n",first+last);
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
1234
124894
242323

Output

x
+
cmd
5
5
5
Advertisements

Demonstration


CodeChef solution FLOW004  - ,First and Last Digit CodeChef solution in C,C++

Previous
CodeChef solution FLOW006 - Sum of Digits CodeChef solution in C,C++
Next
CodeChef solution INTEST - Enormous Input Test in Codechef solution in C,C++