+ 4

How this program works. Anyone explain me....

main() { int i; int j; for (i=1;i<=10;i++) { for(j=0;j<=i;j++) printf("%d",i); printf("\n"); } }

24th Mar 2017, 3:50 AM
Pravin
Pravin - avatar
1 Answer
+ 25
1 1 2 2 2 3 3 3 3 and so on... for stating it, i takes the value 1 and goes inside another for loop.. here j gets the value 0 and is less than or equal to i (i.e 1 now) so it goes to printf and prints i for j=0 and j=1. so you get two times 1 in output.. same for i=2.. j=0,1,2 so 2 is outputted 3 times and so on..
24th Mar 2017, 4:14 AM
Frost
Frost - avatar