English, asked by pardhuking755, 2 months ago

How many times will the following loop get executed?
for x = 5 to 1
for y = 1 to x
print y​

Answers

Answered by malikmayank720
0

Answer:

5

5555555555555555555

Answered by shritik1605sl
0

Answer:

The loop gets executed by  15 times.

Explanation:

This is a nested loop where each inner loop is executed when a outer loop condition satisfies.

#include <stdio.h>

int main()

{

int x,y;

for (x=5;x>=1;x--)

{

   for (y=1;y<=x;y++)

   printf( "%d",y);

}

}

here when x=5 the y loop is executed 5 times.

then  x=4;  the y loop is executed 4 times.

then x=3; the y loop then executes 3 times.

then x=2; the y loop then executes 2 times

then x=1; the y loop then executes  only 1 time.

∴The loop gets executed by 5 + 4 + 3 + 2 + 1 = 15 times.

In general, it will be the summation of value of x in this particular program.

Similar questions