by CodeChum Admin
Manipulating values from a series of numbers is fun, but let's try exploring the use of loops a little more.
How about printing out each digit of a number by place values, in ascending order?
Instructions:
Input
A line containing an integer.
214
Output
Multiple lines containing an integer.
4
1
2
#include <iostream>
using namespace std;
int main(){
int number;
cout<<"Input\nA line containing an integer.\n";
cin>>number;
cout<<"Output\nMultiple lines containing an integer.\n";
cout<<number % 10<<endl;
number /= 10;
while(number != 0){
cout<<number % 10<<endl;
number /= 10;
}
return 0;
}
Comments
Leave a comment