我需要更改三联代码 [英] c++ i need to change tripple code
本文介绍了我需要更改三联代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setw;
#include <cmath>
using std::sqrt;
int main()
{
const int N = 6;
for (int i = 2; i <= N; ++i)
for (int j = 1; j < i; ++j)
for (int k = 0; k < j; ++k)
cout << "(" << k << "," << j << "," << i << ")" << endl;
return 0;
}
输出为:
(0,1,2)
(0,1,3)
(0,2,3)
(1,2,3)
.
.
.
(1,5,6)
(2,5,6)
(3,5,6)
(4,5,6)
我需要更改代码以显示以下内容:
2 1
3 4
4 10
5 20
6 35
7 56
8 84
9120
10165
右边的数字是三组的数字,以左边的数字结尾
谢谢
The output is:
(0,1,2)
(0,1,3)
(0,2,3)
(1,2,3)
.
.
.
(1,5,6)
(2,5,6)
(3,5,6)
(4,5,6)
I need to change the code to show the below:
2 1
3 4
4 10
5 20
6 35
7 56
8 84
9 120
10 165
Right number is the number of triple set which ends with left number
thank you
推荐答案
在代码中添加列表或数组,并在循环中对项目进行计数,然后在最后打印结果.例如:
Add a list or array to your code and count the items as you go through your loop and then print the results at the end. So for example:
int list[10];
int index;
...
index = ???; // where ??? is the ending number
list[index] += 1;
最后,只需迭代您的列表即可打印所有非零的总数.
At the end just iterate your list printing all the non-zero totals.
这篇关于我需要更改三联代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文