What would be the output of the nested for loop given below?

What would be the output of the nested for loop given below?
for(( r=1; i<=5; i++ ))
do
for(( i=1; j<=i; j++ ))
do
echo -n “$j”
done
echo ” “
done

What would be the output of the nested for loop given below?
for(( r=1; i<=5; i++ ))
do
for(( i=1; j<=i; j++ ))
do
echo -n “$j”
done
echo ” “
done

A.
1
12345

B.
12345

C.
12345
12345
12345
12345
12345

D.
12345
12345



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Hector

Hector

creo que esta mal redactado el bucle:
for(( r=1; i<=5; i++ ))

en lugar de "r=1", deberia ser "i=1", haciendo que todo el proceso falle y quede infinito en " ". y el segundo for: deberia ser for(( j=1; j<=i; j++ )), para el anidado.

pasado esto, la respuesta deberia ser:
1
12
123
1234
12345

ya que el echo -n, evita el salto de linea:
man echo:

-n do not output the trailing newline