Pentatope number

Given a number n, find the nth Pentatope number. A pentatope number is represented by the fifth number in any row of Pascal’s Triangle. As it is fifth number, it should start from row having at least 5 numbers. So, it starts from row 1 4 6 4 1. The formula for the nth pentatopic number is: n (n+1) (n+2) (n+3) / 24

Starting Pentatope numbers are : 1, 5, 15, 35, 70, 126, 210, 330, 495…..

Pentatope Numbers:
Pentatope Numbers
In the above figure, red color circled numbers are pentatope numbers.

Examples:

Input : 4
Output : 35

Input : 8
Output : 330

Below is the implementation for nth Pentatope Number :

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP Program to find the
// nth Pentatope number
#include <bits/stdc++.h>
using namespace std;
  
// function for Pentatope
// number
int Pentatope_number(int n)
{
    // formula for find Pentatope
    // nth term
    return n * (n + 1) * (n + 2) * (n + 3) / 24;
}
  
// Driver Code
int main()
{
    int n = 7;
    cout << n << "th Pentatope number :" 
         << Pentatope_number(n) << endl;
  
    n = 12;
    cout << n << "th Pentatope number :" 
         << Pentatope_number(n) << endl;
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to find the nth Pentatope
// number
import java.io.*;
  
class GFG {
  
    // function for Pentatope
    // number
    static int Pentatope_number(int n)
    {
          
        // formula for find Pentatope
        // nth term
        return n * (n + 1) * (n + 2) * 
                         (n + 3) / 24;
    }
      
    // Driver Code
    public static void main (String[] args)
    {
        int n = 7;
        System.out.println( n + "th "
                   + "Pentatope number :"
                  + Pentatope_number(n));
                    
        n = 12;
        System.out.println( n + "th "
                  + "Pentatope number :"
                 + Pentatope_number(n));
    }
}
  
// This code is contributed by anuj_67.

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to find
# nth Pentatope number
  
# Function to calculate
# Pentatope number
def Pentatope_number(n):
  
    # Formula to calculate nth
    # Pentatope number
    return (n * (n + 1) * (n + 2
                 * (n + 3) // 24)
  
# Driver Code
n = 7
print("%sth Pentatope number : " %n,
                    Pentatope_number(n))
n = 12
print("%sth Pentatope number : " %n,
                    Pentatope_number(n))
  
# This code is contributed by ajit.     

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to find the nth Pentatope 
// number
using System;
  
class GFG {
  
    // function for Pentatope
    // number
    static int Pentatope_number(int n)
    {
          
        // formula for find Pentatope
        // nth term
        return n * (n + 1) * (n + 2) * 
                         (n + 3) / 24;
    }
      
    // Driver Code
    public static void Main ()
    {
        int n = 7;
        Console.WriteLine( n + "th "
                + "Pentatope number :"
               + Pentatope_number(n));
                 
        n = 12;
        Console.WriteLine( n + "th "
                + "Pentatope number :"
               + Pentatope_number(n));
    }
}
  
// This code is contributed by anuj_67.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP Program to find the
// nth Pentatope number
  
// function for Pentatope
// number
function Pentatope_number($n)
{
      
    // formula for find Pentatope
    // nth term
    return $n * ($n + 1) * 
          ($n + 2) * ($n + 3) 
                       / 24;
}
  
    // Driver Code
    $n = 7;
    echo $n , "th Pentatope number :"
            , Pentatope_number($n), "\n";
  
    $n = 12;
    echo $n , "th Pentatope number :"
            , Pentatope_number($n) ;
              
// This code is contributed by anuj_67.
  
?>

chevron_right



Output :

7th Pentatope number : 210
12th Pentatope number : 1365

References : https://en.wikipedia.org/wiki/Pentatope_number/



My Personal Notes arrow_drop_up


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.



Improved By : vt_m, jit_t