Example :
0 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3
Program :
#include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); for(i=0;i<=9;i++) { for(j=0;j<(1+2*i);j++) printf("%d",i); printf("\n"); } getch(); }
Explanation :
for(j=0;j<(1+2*i);j++)
- Outer for loop Indicates “How Many Lines is to be printed ?“
- Inner For Loop Tells “How many Numbers are printed on Single Line ?“
Explain It ??
When i = 0 Number of Values Printed = 1 + 2i = 1 + 2(0) = 1 When i = 1 Number of Values Printed = 1 + 2i = 1 + 2(1) = 3 When i = 2 Number of Values Printed = 1 + 2i = 1 + 2(2) = 5