Nesting of For loops:
1#include <stdio.h>2 3 intMainintargcConst Char*argv[]) {4 //Print out the "*" of the rectangle5 //Control Prints 5 lines6 //The first way of understanding: to print a line of code, executed 5 times7 for(intj=0; j<5; J + +) {8 //Print a line *, with 59 Ten for(intI=0;i<5; i++){ Oneprintf"*\t"); A } -printf"\ n"); - } the - /* - //Outer control row count, Inner control column number - j=0 + i=0 - I=1 + i=2 A i=3 at i=4 - j=1 - i=0 - I=1 - i=2 - i=3 in i=4 - j=2 to i=0 + I=1 - i=2 the i=3 * i=4 $ j=3Panax Notoginseng i=0 - I=1 the i=2 + i=3 A i=4 the j=4 + i=0 - I=1 $ i=2 $ i=3 - i=4 - */ the -printf"\ n");Wuyi return 0; the}
* * * * * * * * * * * * * * * * * * * * * * * * *
---------------------------------------------------------------
For loop nesting applications: printing graphics
1#include <stdio.h>2 voidtest1 () {3 4 5 //Print a square6 for(inti =0; i<5; i++) {7 for(intj=0; j<5; J + +) {8printf"* ");9 }Tenprintf"\ n"); One } A -printf"\ n"); - //Print Positive triangle the for(inti =0; i<5; i++) { - - //9*9 Multiplication table j<=i x line print x - for(intj =0; j<=i; J + +) { +printf"* "); - } + Aprintf"\ n"); at } - -printf"\ n"); - - //Print Inverted triangle - for(inti =0; i<5; i++) { in - //j<5-i, line 1th prints 5, the second line prints 4 to for(intj =0; j<5-I.; J + +) { +printf"* "); - } the *printf"\ n"); $ }Panax Notoginseng - } the + //Side Triangles A voidtest2 () { the + //Print Positive triangle - for(inti =0; i<5; i++) { $ $ //9*9 Multiplication table j<=i x line print x - for(intj =0; j<=i; J + +) { -printf"* "); the } - Wuyiprintf"\ n"); the } - Wu //Print Inverted triangle - for(inti =0; i<5; i++) { About $ //j<5-i, line 1th prints 5, the second line prints 4 - for(intj =1; j<5-I.; J + +) { -printf"* "); - } A +printf"\ n"); the } - $ the } the intMainintargcConst Char*argv[]) { the the test1 (); - test2 (); in for(inti =1; i<=5; i++) { the the //9*9 Multiplication table j<=i x line print x About for(intj =1; j<=i; J + +) { theprintf"%d", j); the } the +printf"\ n"); - } the Bayi the return 0; the}
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
----------------------------------
Print Graphics as required:
* *** ***** ******* ********* ***********
<09> nested +for loop nested applications for loops: Print graphics + print graphics as required +