Write a counting loop that initializes an int variable called begin to 2 and dou
ID: 3760921 • Letter: W
Question
Write a counting loop that initializes an int variable called begin to 2 and doubles this value
each iteration until it reaches 65,536. The loop will contain a single line that increments the
value of an int variable called counter.
for ( int begin = 2; begin < 65536; begin * 2 )
{
counter++;
}
18. If the counter is initialized to 0 within counting loop in the question above(before incremented), what
will the value of counter be when the loop ends? this is what need help with
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int begin = 2;
int counter = 0;
for(begin=2;begin<65536;begin*=2)
counter++;
cout << counter;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int begin = 2;
int counter = 0;
for(begin=2;begin<65536;begin*=2)
{
counter = 0;
counter++;
}
cout << counter;
return 0;
}
Value of counter = 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.