Summary: double for the cycle class print triangle graphic

1, the outer layer controls the row number, column number of the inner control.

2, when the number of columns and rows hook:

  First determine the number of lines to be printed whether the relationship between things,

  If so, the analysis depending on the circumstances. (Such as the multiplication table)

int main(void)
{
    @ 1 * 1 at the top left 
    for ( int I = 1 ; I <= . 9 ; I ++ )
    {
        for (int j = 1; j <= i ; j++)
        {
            printf("%dx%d=%d ", j, i, i*j);
        }
        printf("\n");
    }

    @ 1 * 1 in the lower left 
    for ( int I = . 9 ; I> = 1 ; i-- )
    {
        for (int j = 1; j <= i ; j++)
        {
            printf("%dx%d=%d ", j, i, i*j);
        }
        printf("\n");
    }

    @ 1 * 1 in the upper right corner       
    for ( int I = 1 ; I <= . 9 ; ++ I)  
    {
        for ( int J = . 9 ; J> I; --j) // printing space    
        {
            printf("\t"); 
        }
        for ( int K = I; K> = . 1 ; - K) // Print equation       
        {
            printf("%dx%d=%2d  ", i, k, i*k);
        }
        printf("\n");
    }

    @ 1 * 1 in the lower right corner 
    for ( int I = . 9 ; I> = 1 ; - I)
    {
        for ( int J = . 9 ; J> I; --j) // printing space       
        {
            printf("\t");
        }
        for ( int K = I; K> = . 1 ; - K) // Print equation       
        {
            printf("%dx%d=%2d  ", i, k, i*k);
        }
        printf("\n");
    }

    system("pause");
}

 Like inside   @ 1 * 1 In the lower left corner   of the outer loop is defined as the initial condition has a 9. 

  If not, I used to default the outer loop increments (of course, you can also decreasing the outer loop, the inner loop just to turn)

  Thus, in the absence

    1, control the number of columns to increment.

      First, the outer loop increments, set a good inner loop variable end condition let the inner loop and outer loop variable hook. Then the inner loop variable is incremented

    2, control of decreasing the number of columns.

      First, the outer loop increments, set a good inner loop variable end condition let the inner loop and outer loop variable hook. Then the inner loop variable is decremented

 //       *
 //     * * *
 //   * * * * *
 // * * * * * * *
 //   * * * * *
 //     * * *
 //       *
int main(void)
{
    int I = 0 ;
     int J = 0 ;
     int K = 0 ;
     for (I = 0 ; I < 4 ; I ++)     // 4 representatives of 4 rows 
    {
         for (J = 0 ; J < . 7 - 2 * I; J ++ )    // 7 represents a first line of seven per line represents the difference between two 
        {
            printf(" ");
        } 
    // for (J =. 7 - 2 * I -. 1; J> = 0; J,) // Of course, different initial conditions, to turn NATURAL
     // {
      // the printf ( "");
      // }
for (K = 0 ; K < . 1 + 2 * I; ++ K ) { printf("* "); } printf("\n"); } for (i = 0; i < 3; i++) { for (j = 0; j < 3+2*i; j++) { printf(" "); } for (k = 0; k <=4-2*i; k++) { printf("* "); } printf("\n"); } system("pause"); return 0; }

 

     

  

  

  

Guess you like

Origin www.cnblogs.com/asdfknjhu/p/12113831.html