Algorithm
problem Link : https://www.codechef.com/problems/FLOW004
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
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
3
1234
124894
242323
1234
124894
242323
Output
5
5
5
5
5
Demonstration
CodeChef solution FLOW004 - ,First and Last Digit CodeChef solution in C,C++