/****************************************************** ** Name: ** Filename: 5digit.cpp ** Project #: Deitel & Deitel 1.36 ** Project Description: Write a program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from on another by three spaces each. ** Output: Five-digit number separated by three spaces ** Input: Five-digit number ** Algorithm: Explain function to be performed. Direct user to input a five digit number. Take the five digit number and divide by 10 then hold the remainder, to be printed later then divide the previous answer excluding the remainder and again hold the new remainder of the new answer. Continue till five remainders are obtained which also will be the same digits as the five original digits that were input. Print out the five remainders in order from the last obtained to the first, inserting spaces in between. ******************************************************/ // Include files #include // used for cin, cout #include using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section int num1, a, a1, b, b1, c, c1, d, d1, e; // Executable section instruct (); cout << "Enter a five digit number: "; cin >> num1; if ( num1 >= 100000 ) cout << "**** You entered more than five digits ****" << endl; a = num1 % 10; a1 = num1 / 10; b = a1 % 10; b1 = a1 / 10; c = b1 % 10; c1 = b1 / 10; d = c1 % 10; d1 = c1 / 10; e = d1 % 10; if ( num1 <= 99999 ) cout << e << " " << d << " " << c << " " << b << " " << a << endl; pause (); return 0; } void instruct (void) { // Declaration section // Executable section cout << "Enter a five digit number below. The program will then\n" << "take the five digit number that has been input and print\n" << "the digits separated from one another by three spaces each.\n " << endl; } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output Enter a five digit number below. The program will then take the five digit number that has been input and print the digits separated from one another by three spaces each. Enter a five digit number: 42339 4 2 3 3 9 Press any key to continue... */