View Single Post
  #2  
Old 03-01-2004, 10:50 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

http://people.uncw.edu/tompkinsj/112...36solution.cpp

// Exercise 1.36 Solution
#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
int num;

cout << "Enter a five-digit number: ";
cin >> num;

cout << num / 10000 << " "; //prints the left most digit (5th)
num = num % 10000; //assigns a new value to num -four digits
cout << num / 1000 << " "; //prints the left most digit (4th)
num = num % 1000; //assigns a new value to num -three digits
cout << num / 100 << " "; //prints the left most digit (3rd)
num = num % 100; //assigns a new value to num -two digits
cout << num / 10 << " "; //prints the left most digit (2nd)
num = num % 10; //assigns a new value to num -one digit
cout << num << endl; //prints the last digit of num and a newline

return 0;
}
Reply With Quote