107k views
3 votes
Write a while loop that prints that number doubled without reaching 100. Follow each number with a space. After the loop, print a newline. Ex: If num Insects = 8, print: 8 16 32 64

1 Answer

3 votes

Answer:

The program to this question as follows:

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

int n; //defining integer variables

cout<<"Enter number: "; //message

cin>>n; //input value by user

while (n< 100) //loop for check condition

{

cout<<n<<" ";//print value

n=n*2; //calculate value

}

return 0;

}

Output:

Enter number: 8

8 16 32 64

Step-by-step explanation:

In the above C++ language code, a header file is included, then defining the main method, inside the method an integer variable n is defined, which is used for user input for calculating their double number.

In the next step, The while loop is declared, and the loop variable n range is defined, that its value is less than 100, inside the loop the variable n is used to calculate, its double number, and print function "cout" to print its value.

User Starlette
by
4.7k points