// // Program to test largestPowerOf2LE function. // // Input: integer n. // Output: largest m such that 2 to the m power <= n. // #include #include // has EXIT_SUCCESS // pre: n > 0. // post: return value is the largest integer m such that // 2 to the m power is <= n. int largestPowerOf2LE(int n) { int count = 0; while (n >= 2) { n /= 2; ++count; } return count; } // ---- main program ---- int main(void) { int temp; cout << "Enter a positive integer:\n"; cin >> temp; if (temp > 0) cout << largestPowerOf2LE(temp) << endl; else cout << "Bad input\n"; return EXIT_SUCCESS; }