// this program initializes an array // of 20 elements to 0's and then reads // an arbitrary number (<= 20) of numbers // and stores them in the array. // End of file indicated by number -9999 // It then prints out the contents of the // resulting array. #include #include main() { const int arraysize = 20; int numbs[arraysize] = {0}; int i, count = 0; cout << "Array numbs initialized to 0" << endl; cout << "Array element" << setw(10) << "Contents" << endl; for (i = 0; i < arraysize; i++) cout << setw(8) << "numbs[" << setw(2) << i << "]" << setw(10) << numbs[i] << endl; cout << endl; // read in array elements cin >> numbs[count]; while(( numbs[count] ) != -9999) { cin >> numbs[++count]; } // print out new array contents cout << "Array numbs read as input" << endl; cout << "Array element" << setw(10) << "Contents" << endl; for (i = 0; i <= count - 1; i++) cout << setw(8) << "numbs[" << setw(2) << i << "]" << setw(10) << numbs[i] << endl; cout << endl; return 0; }