Ask Question

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.

+4
Answers (1)
  1. 15 June, 05:21
    0
    The program to this question as follows:

    Program:

    #include / /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<
    squ++; / /increment value by 1

    }

    cout<
    n=1; / /change the value of n

    cout<<"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++; / /increment value of n by 1

    }

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

    n=1; / /holing value in n

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

    {

    cout<
    n=n*2; / /calculate value

    }

    return 0;

    }

    Output:

    Square between 0 to 100 : 0 1 4 9 16 25 36 49 64 81 100

    Positive number, which is divisible by 10: 10 20 30 40 50 60 70 80 90

    Powers of two less than n: 1 2 4 8 16 32 64

    Explanation:

    In the above program, two integer variable "squ and n" is defined, then three while loop is declared, which is used to calculate different values, that can be described as follows:

    In the first while loop both "n and squ" variable is used, in which n is used for check range and "squ" is used to calculate the square between 1 to 100. The second, while it is used to calculate the positive number, which is divisible by 10, in this only n variable is used, that calculates the value and check its range. Then the last while loop is used which is used to calculate the double of the number, which is between 1 to 100 range.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers