// // Program: reverse-and-print // // Purpose: print input in reverse order // // Input: sequence of numbers x1, x2, .. xN, from standard input. // // Output: x1, x2, .. xN printed to standard output in reverse order // (xN, .... x2, x1). // #include #include // has EXIT_SUCCESS using namespace std; // Function to read numbers in and print them in reverse order. // Pre: User has been prompted to enter numbers, control-D to end. // Post: Numbers entered by user have been printed in reverse order. void read_and_print(void) { int num; if (cin >> num) // read in number and test { read_and_print(); cout << num << endl; } else cout << "Here are the numbers you entered, in reverse order:\n"; return; } // Main program. int main(void) { cout << "Enter some integers, control-D to end:\n"; read_and_print(); return EXIT_SUCCESS; }