codeup exercises

Title description

Output the following 4*5 matrix

  1  2  3  4  5

  2  4  6  8 10

  3  6  9 12 15

  4  8 12 16 20

It is required to use a loop to achieve, pay attention to the output of 5 numbers per line, each number occupies the width of 3 characters, right-aligned.

 

enter

no

Output

Output 5 numbers per line, each number occupies 3 characters width, right-justified.

 

Sample input Copy

no

Sample output Copy

  1  2  3  4  5
  2  4  6  8 10
  3  6  9 12 15
  4  8 12 16 20

AC code:

#include<cstdio>
using namespace std;
int main()
{
    //i表示行,j表示列
    for (int i = 1; i <= 4;i++){
        for (int j = 1;j <= 5;j++){
            printf("%3d",i * j);
            if ((i * j) % 5 == 0) printf("\n");
        }
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/smallrain6/article/details/106984554