+ 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; }
1 Answer
+ 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!