/******************************************************************************************* 04-B.CPP answer to problem B, Practical #4 *******************************************************************************************/ #include <iostream.h> void GetResults(double list[], const int size); void DisplayResults(double list[], const int size); double pow2(const int n); void main() { const int maxsize = 20; double PowersOfTwo[maxsize]; cout << "This program displays the powers of 2" << endl << "of the numbers from 0 to 19" << endl << endl; GetResults(PowersOfTwo, maxsize); DisplayResults(PowersOfTwo, maxsize); } void GetResults(double list[], const int size) { for (int i = 0; i < size; i++) { list[i] = pow2(i); } } void DisplayResults(double list[], const int size) { cout << " n" << "\t 2^n" << endl << "---" << "\t------" << endl; for (int i = 0; i < size; i++) { cout << i << '\t' << list[i] << endl; } } double pow2(const int n) { double result = 1; for (int i = n; i > 0; i--) result = result * 2; return result; }