80.3k views
1 vote
Write a for loop that prints the values 1 2 4 8 16 32 64 by increasing the value of a counting variable by a factor of two in each cycle.

User RobC
by
5.0k points

1 Answer

4 votes

Answer:

Following code is in C++.

#include <iostream>

using namespace std;

int main() {

int count=1;

for(int i=1;i<=6;i++)

{

count*=2; //multiplying the count variable.

cout<<count<<" "; //printing the variables.

}

return 0;

}

Output:-

2 4 8 16 32 64

Step-by-step explanation:

I have initialized a variable count with the value 1 after that I have ran a loop from 1 to 6 and in each iteration in the loop the count variable is multiplied by 2.After that just printing the output.

User Shushanth Pallegar
by
5.2k points