Write a program in C++ to read a positive integer number n from a standard input device and to display the number and digit. For example, n = 5678 Output 5 6 7 8 vertically
#include <iostream>
#include <list>
using namespace std;
int main()
{
int n;
list<int>l;
cout << "Please, input a number: ";
cin >> n;
while (n > 0)
{
l.push_front(n % 10);
n /= 10;
}
list<int>::iterator it;
for (it = l.begin(); it != l.end(); it++)
{
cout << *it << endl;
}
}
Comments
Leave a comment