Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@varsha0802-YohNRX • May 9, 2011
Nested loops are loops which run inside other loops.
Program for displaying a pyramid:
#include<stdio.h>
int main()
{ int i,j,k;
for(i=1;i<=5;i++)
{ for(k=5;k>=i;k--)
printf(" ");
for(j=2;j<=2*i;j=j+1)
{ printf("*");
}
printf("\n");
}
return(0);
}
Here, two loops are running inside a for loop. Therefore, the loops are nested. -
@praveenkumar-66Ze92 • May 9, 2011
@Varsha, it would be better to write the coding inside the code tags...
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { for(k=5;k>=i;k--) printf(" "); for(j=2;j<=2*i;j=j+1) printf("*"); printf("\n"); } return(0); } -
@varsha0802-YohNRX • May 10, 2011
Ok i'll keep it in mind from the next time. Thanks for pointing in out.praveenscience@Varsha, it would be better to write the coding inside the code tags...
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { for(k=5;k>=i;k--) printf(" "); for(j=2;j<=2*i;j=j+1) printf("*"); printf("\n"); } return(0); }