给定输出的逻辑是什么
what would be the logic for the given output
这是一个模式程序的输出。我发现很难找到以下输出的逻辑。请用C++编写代码...
输出:
12 93 8 104 7 11 145 6 12 13 15
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n+1][n+1];
int st, ed, inc;
int num = 1;
for(int j = 1; j <= n; j++) {
if(j%2==1) {
st = j, ed = n+1, inc = 1;
} else {
st = n, ed = j-1, inc = -1;
}
for(int i = st; i != ed; i += inc) {
arr[i][j] = num;
num++;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
输入: 5
输出:
12 9
3 8 10
4 7 11 14
5 6 12 13 15
相关文章:
- 为对象分配整数.输出将是什么?
- 以下与指针相关的代码的输出是什么?
- 从 c++ 中的实例化进程获取输出的可靠方法是什么?
- 我的输出结果是 0 英寸C++.可能是什么问题
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 以下程序在 c++ 中的输出是什么?
- 任何人都解释下面的代码,它的输出是什么?
- 当我打印字符串时,我不知道它是什么输出
- 假设包含所有必需的头文件,输出将是什么
- 如果我获得Integer和Double的产品,输出的数据类型是什么
- Qimage :: Pixel函数的10位输出特别是指的是什么
- 是什么导致异常输出以及如何修复
- C++程序的输出与预期不同的原因是什么?
- 给定输出的逻辑是什么
- 这段代码的输出是什么,它在构造函数中使用 strcpy?
- 将在 C++ 中输出多维数组内容的 for 循环的结构是什么
- 以下代码的输出是什么(答案因差异编译器而异)
- 在一行C 中,该代码后缀和前缀的输出的逻辑是什么
- 该代码将如何工作以及输出的输出是什么
- 在不同于依赖DLL的文件夹中输出已编译目标的正确方法是什么