Write a program that takes a non-negative long as input and displays each of the digits on a
separate line. The program output should look similar to:
Enter an integer: 71345
7
1
3
4
5
can someone help and explain to me how to do this question, I have no idea where to start.
void print_vertical( unsignedlonglong n )
{
if( n > 0 ) // if at least one digit is left
{
if( n < 10 ) std::cout << n << '\n' ; // only one digit, print it on a line by itself
else // n has more than one digit
{
print_vertical( n/10 ) ; // print the more significant (left-most) digits first
std::cout << n%10 << '\n' ; // and after that, print the last digit on a line by itself
}
}
}
#include <iostream>
#include <string>
int main()
{
unsignedint number ;
std::cin >> number ;
for( auto i : std::to_string(number) ) std::cout << i << '\n' ;
}