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

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP