คำอธิบายโปรแกรม
เลขเพนทาโตป (Pentatope Number) คือตัวเลขในเซลล์ที่ 5 ของแถวใดๆ ในสามเหลี่ยมปาสกาล (Pascal's Triangle) เริ่มจากแถวที่มี 5 พจน์: 1 4 6 4 1 ไม่ว่าจะอ่านจากซ้ายไปขวาหรือขวาไปซ้าย
ตัวเลขเพนทาโตปแรกๆ คือ:
1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365
เลขเพนทาโตปอยู่ในกลุ่ม figurate numbers ซึ่งสามารถแทนได้ด้วยรูปแบบเรขาคณิตที่เป็นระเบียบ สูตรสำหรับพจน์ที่ n คือ:
$$\binom{n+3}{4} = \frac{n(n+1)(n+2)(n+3)}{24}$$
อัลกอริทึม
รับพจน์ที่ N จากผู้ใช้ เพื่อหาเลขเพนทาโตป
ใช้สูตร:
$$\binom{n+3}{4} = \frac{n(n+1)(n+2)(n+3)}{24}$$
ตัวอย่างโค้ด
/* Program to print pentatope numbers upto Nth term */
#include <stdio.h>
int main() {
int n, n1, nthterm, nthterm1, i;
// clrscr();
printf("\n 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("\n\n");
printf("Printing the Pentotope Numbers upto Nth Term");
printf("\n Print Pentatope Numbers till the term: ");
scanf("%d", &n1);
printf("\n\n");
printf("The Pentotope Numbers are:\n\n");
for (i = 1; i <= n1; i++) {
nthterm1 = (i * (i + 1) * (i + 2) * (i + 3) / 24);
printf("%d\t", nthterm1);
}
// getch();
return 0;
}
เอาต์พุต
แสดงเลขเพนทาโตปตามพจน์ที่กำหนด