Dependent Quadratic Loops in C

Notes:

Dependent Quadratic Loops in C Programming Language:

Case 3: Dependent quadratic loop: for printing patterns
-is a nested loop where
- inner loop iterations depend upon the outer loop counter variable value

for( i=0; i<n; i++ ) // outer for loop
{
for( j=0; j<i; j++ ) // inner for loop
{
statement(s);
}
}

Note:
1. If outer loop counter variable value is 0 then inner loop statements are executed 0 times
2. If outer loop counter variable value is 1 then inner loop statements are executed once
3. If outer loop counter variable value is 2 then inner loop statements are executed twice
4. If outer loop counter variable value is 3 then inner loop statements are executed thrice
5. if outer loop counter variable value is 4 then inner loop statements are executed 4 times
and so on…
6. if outer loop counter variable value is n then inner loop statements are executed n times

Ex:
int i=0;
int j=0;

for( i=0; i<3; i++)
{
for( j=0; j<i; j++)
{
printf(“*”);
}
printf(“\n”);
}

Note:
Dependent quadratic loop can be used to generate various patterns of numbers and stars