Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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 << "
";
	}
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #First #Last #Digit #codechef #solution
ADD COMMENT
Topic
Name
6+9 =