通过嵌套循环输出二维矩阵

输出以下4*5的矩阵。

复制代码
    1    2    3    4    5
    2    4    6    8   10
    3    6    9   12   15
    4    8   12   16   20

输入格式:

无。

输出格式:

二维矩阵

代码如下:

cs 复制代码
#include <stdio.h>
int main() {
    for (int i = 1; i <= 4; i++) {//行
        for (int j = 1; j <= 5; j++) {//列
            if (j == 5) {
                printf("%5d\n", i * j);
            } else {
                printf("%5d", i * j);
            }
        }
    }
    return 0;
}
相关推荐
朝朝辞暮i14 小时前
C++ 第 39 章: 阶段性总复习——类、对象、构造、继承、this、指针与智能指针
开发语言·c++·算法·ros2
垆边人似月.14 小时前
华为题:污染水域
算法
All for pursuit.14 小时前
【回溯-6】79.单词搜索
数据结构·c++·算法·leetcode
ZhangJun9514 小时前
Mobike 共享单车分析项目
人工智能·python·算法·kmeans·聚类·knn
Navigator_Z14 小时前
LeetCode //C - 1281. Subtract the Product and Sum of Digits of an Integer
c语言·算法·leetcode
薛定e的猫咪15 小时前
(AISTATS 2023)BaCaDI 逐章阅读
人工智能·深度学习·算法·机器学习
Benny_Tang15 小时前
AT_arc180_d [ARC180D] Division into 3 题解
数据结构·c++·算法
殷色玫瑰15 小时前
C++ STL:stack、queue、priority_queue 与容器适配器详解
java·开发语言·数据结构·c++·算法·visualstudio
Evand J16 小时前
【电机滤波例程1】PMSM永磁同步电机转速与位置估计,MATLAB程序:标准无迹卡尔曼滤波、模型说明与仿真验证
算法·matlab·电机·ekf·负载·卡尔曼滤波
打码的老程是远篁16 小时前
手把手教你玩转大模型——3. Transformer 的位置编码——模型怎么知道谁在前,谁在后?
人工智能·算法