Ask Question

Assume the int variable value has been initialized to a positive integer. Write a while loop that prints all of the positive divisors of value. For example, if values is 28, it prints divisors of28: 1 2 4 7 14 28

+5
Answers (1)
  1. 11 May, 22:38
    0
    The program to this question can be given as:

    Program:

    #include / /header file.

    using namespace std; / /using namespace

    int main () / /main function.

    {

    int value=28, x=1; / /define variable.

    cout<<"divisors of "<< value <<":"; / /print value.

    while (x < = value) / /loop

    {

    if ((value % x) = =0) / /if block

    cout<<" "<
    x++; / /increment value.

    }

    return 0;

    }

    Output:

    divisors of 28: 1 2 4 7 14 28

    Explanation:

    The description of the above c+ + program can be given as:

    In this program firstly we include a header file. Then we define a main method. In this method we define a variables that is "value and x" and assign a value that is "28 and 1". The variable "x" is used to calculate the value of divisors and print its values and then we print the value variable value. Then we define a while loop. It is an entry control loop in this loop, we check the condition that the variable x is less than equal to value. In this loop, we use a conditional statement. In the if block we define condition that is variable value modular variable x is equal to 0. if this condition is true it will print the value and increment value of variable x. When variable x is greater than and equal to value variable it will terminate the loop and print the value.

    So, the output of this program is "1 2 4 7 14 28".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume the int variable value has been initialized to a positive integer. Write a while loop that prints all of the positive divisors of ...” 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