#include #include using namespace std; int main() { // create an array of 16 integers int numbers[16]; double grades[10]; // an array of 10 doubles string names[100]; // array of string elements // use [] to access array elements numbers[0] = 12; numbers[1] = numbers[0] + 15; numbers[0] += 5; cout << numbers[0] << " and " << numbers[1] << endl; // how about uninitialized elements? // cout << numbers[2] << " and " << numbers[3] << endl; // typically we initialize all values // using a for loop for ( int i = 0 ; i < 16 ; i++ ) { numbers[i] = 0; } // how can we set the numbers array to // be powers of two? // // 0 // numbers[0] = 2 = 1 // // 1 // numbers[1] = 2 = 2 // // 2 // numbers[2] = 2 = 4 // // etc. for ( int i = 0 ; i < 16 ; i++ ) { numbers[i] = pow( 2.0, i ); } // display all values in the array: for ( int i = 0 ; i < 16 ; i++ ) { cout << numbers[i] << endl; } // Fibonacci sequence: // f[0] = 0 // f[1] = 1 // f[n] = f[n-1] + f[n-2]; // Create an array to hold the first 20 Fibonacci numbers // Use a for loop to initialize the array int fib[20]; // initialize the values: fib[0] = 0; fib[1] = 1; for ( int i = 2 ; i < 20 ; i++ ) { fib[i] = fib[i-1] + fib[i-2]; } // Print out the 20th Fibonacci number: cout << "The 20th Fibonacci number is: " << fib[19] << endl; return 0; }