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.

Respuesta :

Answer:

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.

ACCESS MORE
EDU ACCESS
Universidad de Mexico