Nesting of Loops (pattern) in C Language
In C Language we can place loop inside loop that is called Nesting of Loop. In Nesting of Loop, Inner loop executes (X*Y) ( X is outer loop , Y is Inner Loop).
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++) //outerloop 5 times (Row)
{
for(j=1;j<=10;j++)
{
printf("%d ",j); //prints 1 to 10 in a row as no \n is placed
}
printf("\n");//New Line After Row completes
}
getch();
}
If we place printf(“%d “,i) (i in place of j) then it will print value of i and output will be
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5