Search⌘ K
AI Features

Challenge: The Nearest Power of 2

Explore how to create a C++ program that identifies the nearest power of 2 to any positive number. Learn to use loops and decision-making statements effectively while handling edge cases, which enhances your understanding of control flow in programming.

Task

Write a program that takes a positive number (num) and finds the power of 22 nearest to that number. The program stores the resulting value to pwr.

If there are two candidate values, display the smaller one. For example, 22 ...