// This program demonstrates the basics of 1-D arrays #include #include #include #include using namespace std; int main() { const int SizeOfA = 50; int A[SizeOfA]; // an integer array that will hold 50 values indexed from 0 to 49 char C[SizeOfA]; // a char array int i,j, count = 0; srand(time(NULL)); for (i = 0; i < SizeOfA; i ++) A[i] = rand()%100; // place in array element indexed by 'i' a random # from 1 - 99 // walk through the array to see the individual elements cout << "The array A has elements: " << endl; for (i = 0; i < SizeOfA; i ++) { cout << setw(3) << A[i] << " "; count ++; // only here to make the output more readable if (count == 10) { cout << endl; count = 0; } } // let's now fill a char array with random letters for (i = 0; i < SizeOfA; i ++) C[i] = char(rand()%26 + (int)'a'); // walk through the array to see the individual elements count == 0; cout << "The array A has elements: " << endl; for (i = 0; i < SizeOfA; i ++) { cout << setw(3) << C[i] << " "; count ++; // only here to make the output more readable if (count == 10) { cout << endl; count = 0; } } cout << endl; }