在 C 中列印 N 項五稜體數的程式
程式說明
五稜體數是帕斯卡三角形中從第 5 項的 1 4 6 4 1 行開始的任一行的第五個單元格中的數字,可以從左到右或從右到左讀取。
這種型別的數的前幾個數字是
1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365
五稜體數屬於圖形數類,可以表示為規則的離散幾何圖形。第 n 個五稜體數的公式為
$$\left(\begin{array}{c}n+3\ 4\end{array}\right)=\left(\frac{n(n+1)+(n+2)+(n+3)}{24}\right)=\left(\frac{n^2}{4!}\right)$$
演算法
從使用者處接受第 N 項以查詢五稜體數。
使用公式
$$\left(\begin{array}{c}n+3\ 4\end{array}\right)=\left(\frac{n(n+1)+(n+2)+(n+3)}{24}\right)=\left(\frac{n^2}{4!}\right)$$
示例
/* Program to print pentatope numbers upto Nth term */ #include<stdio.h> int main() { int n, n1, nthterm, nthterm1, i; clrscr(); printf("
Please enter the nth term to print Pentatope: "); scanf("%d",&n); nthterm = n * (n + 1) * (n + 2) * (n + 3) / 24; printf("The Pentotpe Number is: "); printf("%d", nthterm); printf("
"); printf("Printing the Pentotope Numbers upto Nth Term"); printf("
Print Pentatope Numbers till the term: "); scanf("%d",&n1); printf("
"); printf("The Pentotope Numbers are:"); printf("
"); for (i = 1; i <= n1; i++){ nthterm1 = (i * (i + 1) * (i + 2) * (i + 3) / 24); printf("%d\t", nthterm1); } getch(); return 0; }
輸出
廣告