将响应限制为每行十个五边形数
limiting responses to ten Pentagonal numbers per line
我正在编写一个代码,要求每行五边形数限制为10,但我无法使其工作。我的代码是:
#include <iostream>
using namespace std;
int getPentagonalNumber(int n)
{
/*equation to calculate pentagonal numbers*/
return (n * (3 * n - 1) / 2);
}
int main()
{
/*Ask the user to put in the number of results*/
int userInput;
cout << "How many pentagonal numbers would you like to be displayed: ";
cin >> userInput;
cout << endl;
cout << "results are: " << endl;
/*Loop to generate the numbers for the equation*/
for (int n = 1; n <= userInput; n++)
{
cout << getPentagonalNumber(n) << " ";
}
return 0;
}
这能满足你的要求吗:
#include <iostream>
using namespace std;
int getPentagonalNumber(int n)
{
/*equation to calculate pentagonal numbers*/
return (n * (3 * n - 1) / 2);
}
int main()
{
/*Ask the user to put in the number of results*/
int userInput;
cout << "How many pentagonal numbers would you like to be displayed: ";
cin >> userInput;
cout << endl;
cout << "results are: " << endl;
/*Loop to generate the numbers for the equation*/
for (int n = 1; n <= userInput; n++)
{
cout << getPentagonalNumber(n) << " ";
if (n % 10 == 0)
cout << endl;
}
return 0;
}
每当n被10整除时,我就添加一个新行输出。
相关文章:
- 在 c++ 中从文本文件中读取两个十六进制值
- 将40个字节长的数据框从十六进制转换为二进制,然后转换为十进制
- 每秒需要发送十个周期的数据(每秒十个周期)
- 在 c++ 中使用字符串流将 4 个字符的十六进制字符串转换为有符号的短字符串
- 两个派生类(十六进制 二进制)的虚拟功能
- 甚至是文件中的每个第十个数字,甚至是奇数
- 如何将多个十六进制值连接到一个值
- 我正在制作一个二十一点程序。我目前有两个问题
- 如何添加两个或多个字符的十六进制值
- 将十六进制颜色空间划分为多个仓
- 超过两个数字十六进制
- 如何组织数十个类似的试用块
- 找到 2 个五边形数,其总和和差产生五边形数
- 将响应限制为每行十个五边形数
- 前十个自然数的平方和与平方和之差
- 将数十个非成员函数转换为方法
- 如何返回一个包含十个字符串的数组的引用
- wsprintfW打印只有几十个
- Opengl多个五边形
- 为什么在函数指针或返回函数指针的函数编译前放上几十个*呢?