// Program to read in integers and print in two columns. // // Input: sequence of N integers read from standard input. // Output: input sequence of integers printed to standard output in // two-column format, with first column containing first // (N+1)/2 numbers and second column containing remaining // numbers. // // This version does not use the STL, but uses a dynamic array. #include #include // has EXIT_SUCCESS #include // has NULL using namespace std; typedef unsigned int size_t; int main(void) { // vector v; size_t size = 0; // size of v int * v = NULL; // to point to array of numbers so far int temp; cout << "Enter some integers, control-D to end:\n"; while (cin >> temp) { //v.push_back(temp); int * temp_v = v; v = new int[size+1]; for (unsigned int j = 0; j < size; ++j) v[j] = temp_v[j]; delete [] temp_v; ++size; v[size-1] = temp; } // size_t size = v.size(); for (size_t i = 0; i < size/2; ++i) cout << v[i] << "\t" << v[i + (size+1)/2] << endl; if (size % 2 != 0) cout << v[size/2] << endl; return EXIT_SUCCESS; }