C ++中居中二十面体编号程序
给定值“n”,任务是生成n的居中二十面体数和中心到二十面体系列直到n并显示结果。
什么是中心二十面体编号?
中心二十面体编号是用于表示二十面体的中心编号(它是具有20个面的多面体图形)。
直到n=1000的前几个中心二十面体数字系列为-
1, 13, 55, 147, 309, 561, 923
中心二十面体数可以使用公式计算-
$$(2n+1)\times\frac{5n^{2}+5n+3}{3}$$
输入值
number: 20
输出结果
Centered Icosahedral Number is : 28741
输入值
number: 12
输出结果
Centered Icosahedral Number is : 6525
算法
Start
Step 1→ declare function to calculate centered iscosahedral number
int calculate(int num)
return (2 * num + 1) * (5 * num * num + 5 * num + 3) / 3
Step 2→ In main() Declare int num = 20
Print calculate(num)
Stop示例
#include <bits/stdc++.h>
using namespace std;
//计算中心二十面体数
int calculate(int num){
return (2 * num + 1) * (5 * num * num + 5 * num + 3) / 3;
}
int main(){
int num = 20;
cout<<"Centered Icosahedral Number is : "<<calculate(num) << endl;
return 0;
}输出结果
如果运行上面的代码,它将生成以下输出-
Centered Icosahedral Number is : 28741