C language brush questions - ninety-nine multiplication table

insert image description here

Article directory

topic

Output a 9*9 multiplication table.
insert image description here

ideas

Considering the rows and columns, a total of 9 rows and 9 columns, double loop, i controls the row, j controls the column, and outputs a multiplication table.

Note the control format.

answer

#include <stdio.h>

int main()
{
    
    
    int i,j,result;

    printf("\n");

    for (i=1;i<10;i++)
    {
    
    
        for(j=1;j<=i;j++)
         {
    
    
             result=i*j;
             printf("%d*%d=%-3d",i,j,result);   // -3d 表示左对齐,占 3 位
         }

        printf("\n");  // 每一行后换行

    }

}


Sample output

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_21484461/article/details/123988129