在 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; }

输出

更新于: 2020年1月9日

185 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.