题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <iostream>
using namespace std;
// 看懂了不代表会做,一定要自己动手写一遍
int main(){
int n;
cin >> n;
int k = 1;
// 观察输出的蛇形矩阵,我们会发现矩阵的每行和每列均为二级等差数列(即数列相邻项的差为等差数列)
for (int i = 0; i < n; ++i){
cout << k << " ";
int tmp = k;
for (int j = i + 1; j < n; ++j){
tmp += j + 1;
cout << tmp << " ";
}
cout << endl;
k += i + 1;
}
return 0;
}
#23届找工作求助阵地##我的实习求职记录##零基础学习C++##14天打卡计划#
