Answer to Question #329976 in C++ for milan

Question #329976

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


1
Expert's answer
2022-04-18T08:40:38-0400
#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;
	}
}







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS