First and the Last Digit
If Given an integer N. Write a program to obtain the sum of the first and last digit of this number.
Input
Output
Constraints
1<= T <= 100
1<= N <=1000000
Example
3
1234
124894
242323
Output
5
5
5
Solution:
#include<stdio.h>
int main()
{
int t,a,b;
unsigned long int n;
scanf("%d",&t);
while(t--)
{
scanf("%lu",&n);
a=n%10;
while(n>=10)
{
n=n/10;
}
b=n%10;
printf("%d\n",a+b);
}
return 0;
}
No comments:
Post a Comment