Last Decimal Digit
Programming Basics · C++
TASK
Problem
In “Last Decimal Digit”, input integer data and print its last decimal digit.
EXAMPLE
Example
7
7
LIMITS
Constraints
0 ≤ n ≤ 10^12.
LEARN
Theory for this problem
+
For non-negative integers, `/` gives the integer quotient and `%` gives the remainder.
Connection to “Last Decimal Digit”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.
NEED HELP?
Hints
+
['Choose division and remainder operations that match the requested decomposition.', 'After solving “Last Decimal Digit”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']
ANSWER
Solution
+
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
cout << n % 10 << '\n';
return 0;
}