我是 C++ 新手。 我正在尝试创建一个程序,其输出如下所示
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
这是我的尝试
#include <iostream>
using namespace std;
int const n=10;
int main (){
int i,j,k,mat[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++){
mat[i][j]=?
}
return 0;
}
最佳答案
解决方案效率低下,但似乎有效:
#include <iostream>
using namespace std;
int const n=10;
int main ()
{
int i, j, mat[n][n] = { 0 };
int indent;
for (indent = 0; indent <= n/2; indent++) {
for (i = indent; i < n-indent; i++) {
for (j = indent; j < n-indent; j++) {
mat[i][j]++;
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cout << mat[i][j] << ' ';
}
cout << endl;
}
return 0;
}
关于c++ - C++ 中的阿兹特克金字塔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30334989/