How exactly can I make a program which will display the digits of a number?
The number can be literally any number, lets say it is 1425. The program needs to print out:
"1 4 2 5"
Is this possible with a while loop?
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
#include <sstream>
int main()
{
int someNumber = 1425;
std::stringstream stream;
stream << someNumber;
char singleChar;
while (stream >> singleChar && std::cout << singleChar << " ");
}
|
Last edited on
Topic archived. No new replies allowed.