Nested Loops


Nested loops that can be placed inside other loops.Although this feature will work with any loop like while,do-while,and for but it is most commonly used with the for loop,because this is easiest to control.A for loop can be used to control the number of times that a particular set statements will be executed.Another outer loop could be used to control the number of times that a whole loop is repeated.


Write a program to print the following pattern


**********
**********
**********
**********
**********


#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=5;j++)
 printf("*")
}
getch();
}



Write a program to print the following pattern


*
**
***
****
*****


#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=5;i++)
{
printf("\n");
for(j=1;j<=i;j++)
print("%d",j);
}
getch();
}

Comments