Answers for "First and Last Digit codechef solution in c++"

C++
0

first and last digit codechef solution

t=int(input())
for i in range(t):
    x=str(input())
    a=int(x[0])
    b=int(x[-1])
    c=a+b
    print(c)
Posted by: Guest on May-20-2020
0

First and Last Digit codechef solution in c++

#include<iostream>
using namespace std;
// Get first number
int first_number(int n)
{
	while (n > 9)
	{
		n /= 10;
	}
	return n;
}
// Get last number
int last_number(int n)
{
	return n %= 10;
}
int main()
{
	int t, n, sum;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		sum = 0;
		sum = first_number(n) + last_number(n);
		cout << sum << "\n";
	}
	return 0;
}
Posted by: Guest on March-07-2022

Code answers related to "First and Last Digit codechef solution in c++"

Browse Popular Code Answers by Language