Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Program to print pentatope numbers upto Nth term in C
A pentatope number is a figurate number that represents the number of points in a pentatope (4-dimensional simplex). These numbers form the fifth diagonal of Pascal's triangle. The nth pentatope number represents the number of ways to choose 4 items from n+3 items.
Syntax
pentatope(n) = n * (n + 1) * (n + 2) * (n + 3) / 24
Mathematical Formula
The formula for the nth pentatope number is −
pentatope(n) = C(n+3, 4) = n * (n + 1) * (n + 2) * (n + 3) / 24
The first few pentatope numbers are −
1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365...
Example: Calculate Nth Pentatope Number
This example calculates and displays the nth pentatope number using the mathematical formula −
#include <stdio.h>
int calculatePentatope(int n) {
return n * (n + 1) * (n + 2) * (n + 3) / 24;
}
int main() {
int n;
printf("Enter the term number: ");
scanf("%d", &n);
int result = calculatePentatope(n);
printf("The %dth pentatope number is: %d<br>", n, result);
return 0;
}
Enter the term number: 5 The 5th pentatope number is: 70
Example: Print Pentatope Numbers up to Nth Term
This example prints all pentatope numbers from the 1st term up to the nth term −
#include <stdio.h>
int calculatePentatope(int n) {
return n * (n + 1) * (n + 2) * (n + 3) / 24;
}
int main() {
int n;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("\nPentatope numbers up to %d terms:<br>", n);
for (int i = 1; i <= n; i++) {
printf("%d ", calculatePentatope(i));
}
printf("<br>");
return 0;
}
Enter the number of terms: 8 Pentatope numbers up to 8 terms: 1 5 15 35 70 126 210 330
Key Points
- Pentatope numbers are the 4th tetrahedral numbers or 5th diagonal of Pascal's triangle.
- The formula involves combinations: C(n+3, 4) where n is the term number.
- Each pentatope number represents points in a 4-dimensional simplex.
- The sequence starts from n=1, giving the first pentatope number as 1.
Conclusion
Pentatope numbers are calculated using the combination formula C(n+3, 4). The simple multiplication and division approach makes it efficient to generate these figurate numbers for mathematical applications.
