Ask 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 consisting of n asterisks. Use no variables other than n.

+4
Answers (1)
  1. 11 July, 05:44
    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 & 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