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;
//calculate Centered Icosahedral Number
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

更新於: 13-8-2020

100 次檢視

開啟你的職業

完成課程獲得認證

開始
廣告
© . All rights reserved.