Write a while loop that prints

A. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81.
B. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90
C. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64.

Respuesta :

Following are the program to the given question:

Program Explanation:

  • Including the header file.
  • Defining the main method inside this, two integer variables, "squ and n", are defined, then three while loops are declared.
  • The loop is used to calculate different values, which can be described as follows:
  • In the first, while loop, both "n" and "squ" variables are used, in which n is used for checking range and "squ" is used to calculate the square between 1 and 100.
  • The second is that while it is used to calculate the positive number, which is divisible by 10, in this case only the n variable is used, which calculates the value and checks its range.
  • In the last while, the loop is used, which is used to calculate the double of the number, which is in the 1 to 100 range.

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

int squ=0,n=0; //defining variable

cout<<"Square between 0 to 100 :"; //message

while(n<100) //loop for calculate Square

{

n=squ*squ; //holing value in n variable

cout<<n<<" "; //print Square

squ++; //increment value by 1

}

cout<<endl; //for new line

n=1; //change the value of n

cout<<"A Positive number, which is divisible by 10: "; //message

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

{

if(n%10==0) //check value is divisible by 10

{

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

}

n++; //increment value of n by 1

}

cout<<endl; //for new line

cout<<"A Powers of two less than n: "; //message

n=1; //holing value in n

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

{

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

n=n*2; //calculate value

}

return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/11512266

Ver imagen codiepienagoya