C language example-realize the output of the multiplication list

  • The first for loop controls the multiplication list to have x rows, and the second for loop controls the yth row to have y columns.
  • \t means data alignment output
#include <stdio.h>
int main()
{
    
    
int m,x,y;
scanf("%d",&m);
for(x=1;x<=m;x++)
{
    
    for(y=1;y<=x;y++)
{
    
    printf("%d*%d=%d\t ",y,x,x*y);
}
printf("\n");
}
return 0}
  • If the multiplication list is output in reverse, the first for loop controls the multiplication list to have x rows, and the second for loop controls the xth row to have x-y+1 columns.
  • The effect of %nd is to occupies the width of n characters when outputting the corresponding variable, and the left part of the insufficient part is filled with a space
#include <stdio.h>
int main()
{
    
    
int x,y;
scanf("%d",&x);
for(;x>=1;x--)
{
    
    for(y=1;y<=x;y++)
{
    
    printf("%2d*%2d=%2d ",y,x,y*x);
}
printf("\n");
}
return 0;
}

Guess you like

Origin blog.csdn.net/qq_41017444/article/details/112404034