# Program to print pentatope numbers upto Nth term

Prerequisites:

Given a value n, and the task is to print pentatope numbers series up to nth term.

Examples:

Input: 5
Output: 1 5 15 35 70

Input: 10
Output: 1 5 15 35 70 126 210 330 495 715


## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Method 1: Using Tetrahedral Number Series:
This problem can be easily solved with the fact that Nth Pentatope Number is equal to the sum of first N Tetrahedral numbers.

Let’s have a look on Series of Pentatope and Tetrahedral Numbers.

For n = 5
Tetrahedral Numbers = 1, 4, 10, 20, 35
Prefix Sum of Tetrahedral numbers for each term: (1), (1 + 4), (1 + 4 + 10), (1 + 4 + 10 + 20), (1 + 4 + 10 + 20 + 35)
So, Pentatope numbers are 1, 5, 15, 35, 70

Calculate Nth Tetrahedral number using formula: So, print the Pentatope Numbers series by generating tetrahedral numbers and adding it with the sum of all previously generated Tetrahedral Numbers.

Below is the implementation of above approach:

## CPP

 // C++ program to generate Pentatope  // Number series  #include  using namespace std;     // Function to generate nth tetrahedral number  int findTetrahedralNumber(int n)  {      return ((n * (n + 1) * (n + 2)) / 6);  }     // Function to print pentatope number   // series upto nth term.  void printSeries(int n)  {      // Initialize prev as 0. It store the      // sum of all previously generated       // pentatope numbers      int prev = 0;      int curr;         // Loop to print pentatope series      for (int i = 1; i <= n; i++)       {          // Find ith tetrahedral number          curr = findTetrahedralNumber(i);             // Add ith tetrahedral number to          // sum of all previously generated           // tetrahedral number to get ith           // pentatope number          curr = curr + prev;          cout << curr << " ";             // Update sum of all previously           // generated tetrahedral number          prev = curr;      }  }     // Driver code  int main()  {      int n = 10;             // Function call to print pentatope      // number series      printSeries(n);             return 0;  }

## Java

 // Java program to generate Pentatope  // Number series  import java.io.*;     class GFG {             // Function to generate nth tetrahedral number      static int findTetrahedralNumber(int n)      {          return ((n * (n + 1) * (n + 2)) / 6);      }             // Function to print pentatope number       // series upto nth term.      static void printSeries(int n)      {          // Initialize prev as 0. It store the          // sum of all previously generated           // pentatope numbers          int prev = 0;          int curr;                 // Loop to print pentatope series          for (int i = 1; i <= n; i++)           {              // Find ith tetrahedral number              curr = findTetrahedralNumber(i);                     // Add ith tetrahedral number to              // sum of all previously generated               // tetrahedral number to get ith               // pentatope number              curr = curr + prev;              System.out.print(curr + " ");                     // Update sum of all previously               // generated tetrahedral number              prev = curr;          }      }         // Driver code      public static void main (String[] args)      {          int n = 10;                 // Function call to print pentatope          // number series          printSeries(n);      }  }

## python3

 # Python program to generate Pentatope  # Number series     # Function to generate nth tetrahedral number  def findTetrahedralNumber(n) :      return (int((n * (n + 1) * (n + 2)) / 6))     # Function to print pentatope number   # series upto nth term.  def printSeries(n) :             # Initialize prev as 0. It store the      # sum of all previously generated       # pentatope numbers      prev = 0        # Loop to print pentatope series      for i in range(1, n + 1) :                  # Find ith tetrahedral number          curr = findTetrahedralNumber(i)             # Add ith tetrahedral number to          # sum of all previously generated           # tetrahedral number to get ith           # pentatope number          curr = curr + prev;          print(curr, end=' ')             # Update sum of all previously           # generated tetrahedral number          prev = curr     # Driver code  n = 10        # Function call to print pentatope  # number series  printSeries(n)

## C#

 // C# program to generate Pentatope  // Number series  using System;     public class GFG {             // Function to generate nth tetrahedral number      static int findTetrahedralNumber(int n)      {          return ((n * (n + 1) * (n + 2)) / 6);      }             // Function to print pentatope number       // series upto nth term.      static void printSeries(int n)      {          // Initialize prev as 0. It store the          // sum of all previously generated           // pentatope numbers          int prev = 0;          int curr;                 // Loop to print pentatope series          for (int i = 1; i <= n; i++)           {              // Find ith tetrahedral number              curr = findTetrahedralNumber(i);                     // Add ith tetrahedral number to              // sum of all previously generated               // tetrahedral number to get ith               // pentatope number              curr = curr + prev;              Console.Write(curr + " ");                     // Update sum of all previously               // generated tetrahedral number              prev = curr;          }      }             // Driver code      static public void Main ()      {          int n = 10;                 // Function call to print pentatope          // number series          printSeries(n);      }  }

## PHP

 

Output:

1 5 15 35 70 126 210 330 495 715


Time Complexity: O(n)

Method 2: Using Pentatope Number Formula:
The formula to find Nth Pentatope number Below is the required implementation:

## CPP

 // C++ program to print Pentatope number series.  #include  using namespace std;     // Function to print pentatope series up to nth term  void printSeries(int n)  {         // Loop to print pentatope number series      for (int i = 1; i <= n; i++)      {          // calculate and print ith pentatope number          int num = (i * (i + 1) * (i + 2) * (i + 3) / 24);                     cout << num << " ";      }  }     // Driver code  int main()  {      int n = 10;             // Function call to print pentatope number series      printSeries(n);      return 0;  }

## Java

 // Java program to print Pentatope number series.  import java.io.*;     class GFG {             // Function to print pentatope series up to nth term      static void printSeries(int n)      {                 // Loop to print pentatope number series          for (int i = 1; i <= n; i++)          {              // calculate and print ith pentatope number              int num = (i * (i + 1) * (i + 2) * (i + 3) / 24);                             System.out.print(num + " ");          }      }             // Driver code      public static void main (String[] args)       {          int n = 10;                 // Function call to print pentatope number series          printSeries(n);      }  }

## python3

 # Python program to print Pentatope number series.     # Function to print pentatope series up to nth term  def printSeries(n) :         # Loop to print pentatope number series      for i in range(1, n + 1) :             # calculate and print ith pentatope number          num = int(i * (i + 1) * (i + 2) * (i + 3) // 24)                     print(num, end=' ');     # Driver code  n = 10        # Function call to print pentatope number series  printSeries(n)

## C#

 // C# program to print Pentatope number series.  using System;     public class GFG {             // Function to print pentatope series up to nth term      static void printSeries(int n)      {                 // Loop to print pentatope number series          for (int i = 1; i <= n; i++)          {              // calculate and print ith pentatope number              int num = (i * (i + 1) * (i + 2) * (i + 3) / 24);                             Console.Write(num + " ");          }      }             // Driver code      static public void Main ()      {          int n = 10;                 // Function call to print pentatope number series          printSeries(n);      }  }

## PHP

 

Output:

1 5 15 35 70 126 210 330 495 715


My Personal Notes arrow_drop_up self motivated and passionate programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.