Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Code Without chaning any code below, could anyone help me to get the second line? Ex1) Please enter a number from 3 to 100:

C++ Code

Without chaning any code below, could anyone help me to get the second line?

Ex1)

Please enter a number from 3 to 100: 6

2, 4 (<--------This is what I need - there should be no comma at the end!)

The answer is 4

Please enter a number from 3 to 100: 100

2, 4, 8, 16, 32, 64 (<-------this is what I need - no comma at the end!)

The answer is 64

#include #include #include using namespace std;

int powerOfTwo(int num);

int main () { int num; int result; int i=1; cout<<"Please enter a number from 3 to 100: "; cin>>num; cout << num << endl; if ((num < 3) || (num > 100)) cout << "Please follow the directions!" << endl; else { int pow; pow = powerOfTwo(num); cout << " The answer is "; cout << pow; cout << endl; } } int powerOfTwo(int num) { int N = num; int v = 1;

while (v <= N/2) v *= 2;

cout< return v; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions