Nested for loop
In C programming language you can use one loop inside another loop.
Syntax:
for (initialization; test condition; increment)
{
{//}for (initialization; test condition; increment)
{
body of the loop
}
}
Example Nested for loop:
{/*} Generation of matrix of given order with all elements 1 {*/}
#include <stdio.h>
#include <conio.h>
int main()
{
int i,j,k;
printf("Enter the dimension of square matrix: ");
scanf("%d",&k);
printf("\nInitializing matrix of order %dX%d ...... \n",k,k);
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
printf("1");
printf("\t");
}
printf("\n");
}
getch();
return;
}