+ 1

anyone explain me this code with proper explaination

And explain nested for loop too int i, j, n; printf("Enter number of rows : "); scanf("%d", &n); for(i=1; i<=n; i++) { for(j=i; j<=n; j++) { printf("*"); } printf("\n"); } return 0; }

20th Aug 2017, 2:21 PM
Jayram
Jayram - avatar
1 Resposta
+ 3
Hello @Jayram. A good C example for nested loops! The first for loop goes through lines (as many as the user input) and the second is on the characters within it. the inner for will write out as many * as the user input minus the number of lines already printed out. So the output will be: Input 2: ** * Input 3: *** ** * Input 4: **** *** ** * etc... Hopes it helped!
20th Aug 2017, 2:46 PM
Hajnal Máté
Hajnal Máté - avatar