SUM OF SPECIFIC NUMBERS
Problem Description
" 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
"
CODING ARENA
#include <stdio.h>
int main()
{
int a,i,s=0,l,d,f;
int n;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&n);
l=n%10;
while(n>0)
{
d=n%10;
s=d;
n=n/10;
}
f=s;
printf("%d\n",l+f);
}
return 0;
}
Test Case 1
Input (stdin)3
1234
124894
242323
Expected Output
5
5
5
Test Case 2
Input (stdin)2
2345
6789
Expected Output
7
15
No comments:
Post a Comment