Ask Question
30 April, 18:22

Given an int variable n that has already been declared and initialized to a positive value, use a while loop to print a single line consisting of n asterisks. Use no variables other than n.

+4
Answers (1)
  1. 30 April, 20:27
    0
    The code to this question can be given as:

    Code:

    int n=5; / /define an integer variable n and assign a positive value.

    while (n > 0) / /define while loop,

    {

    printf ("*"); / /print asterisks.

    n - -; / /decrements value.

    }

    Explanation:

    The description of the above code can be given as:

    In this code we define an integer variable that is "n" and assign a positive value that is "6". Then we define a while loop. It is an entry control loop which means it will check condition first then executes. In this loop, we use variable n and check condition that the value of n is greater than 0. In this loop, we print the asterisks and decrease the value of n. When the variable n value is 0. It will terminate the loop and print asterisks.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given an int variable n that has already been declared and initialized to a positive value, use a while loop to print a single line ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers