SUM OF FIRST AND LAST
Problem Description
If Give an integer N . Write a program to obtain the sum of the first and last digit of this number. The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an integer N. Display the sum of first and last digit of N.
CODING ARENA::
#include <stdio.h>
int main()
{
int a,n,f,l;
scanf("%d",&a);
scanf("%d",&n);
printf("%d",l+n);
return 0;
}
Test Case 1
Input (stdin)1
1234
Expected Output
5
Test Case 2
Input (stdin)1
4545654
Expected Output
8
Given code of "sum of first and last" is incomplete.
ReplyDeletehere is the code for "sum of first and last" in C
#include
#include
int main() {
int a,b,i=10,x;
scanf("%d%d",&a,&b);
a=b%10;
x=b;
int c;
while(i!=0) {
b=b/10;
if(b%10==0) {
break;
}
else {
c++;
}
--i;
}
for (i=0; i<c; i++) {
x=x/10;
}
printf("\n%d",x+a);
return 0;
}