A number is termed as a tetrahedral number if it can be represented as a pyramid with a triangular base and three sides, called a tetrahedron. The n^{th} tetrahedral number is the sum of the first n triangular numbers.

The first ten tetrahedral numbers are:

1, 4, 10, 20, 35, 56, 84, 120, 165, 220, …

Formula for n^{th} tetrahedral number:

T_{n}= (n * (n + 1) * (n + 2)) / 6

**Proof:**

The proof uses the fact that the n^{th}tetrahedral number is given by, Tri_{n}= (n * (n + 1)) / 2 It proceeds by induction.Base CaseT_{1}= 1 = 1 * 2 * 3 / 6Inductive StepT_{n+1}= T_{n}+ Tri_{n+1}T_{n+1}= [((n * (n + 1) * (n + 2)) / 6] + [((n + 1) * (n + 2)) / 2] T_{n+1}= (n * (n + 1) * (n + 2)) / 6

Below is the implementation of above idea :

## C++

`// CPP Program to find the ` `// nth tetrahedral number ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `int` `tetrahedralNumber(` `int` `n) ` `{ ` ` ` `return` `(n * (n + 1) * (n + 2)) / 6; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `n = 5; ` ` ` ` ` `cout << tetrahedralNumber(n) << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the ` `// nth tetrahedral number ` `class` `GFG { ` ` ` `// Function to find Tetrahedral Number ` `static` `int` `tetrahedralNumber(` `int` `n) ` `{ ` ` ` `return` `(n * (n + ` `1` `) * (n + ` `2` `)) / ` `6` `; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `5` `; ` ` ` ` ` `System.out.println(tetrahedralNumber(n)); ` `} ` `} ` ` ` `// This code is contributed by Manish Kumar Rai. ` |

*chevron_right*

*filter_none*

## Python

`# Python3 Program to find the ` `# nth tetrahedral number ` ` ` `def` `tetrahedralNumber(n): ` ` ` ` ` `return` `(n ` `*` `(n ` `+` `1` `) ` `*` `(n ` `+` `2` `)) ` `/` `6` ` ` `# Driver Code ` `n ` `=` `5` `print` `(tetrahedralNumber(n)) ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the ` `// nth tetrahedral number ` `using` `System; ` ` ` `public` `class` `GFG{ ` ` ` ` ` `// Function to find Tetrahedral Number ` ` ` `static` `int` `tetrahedralNumber(` `int` `n) ` ` ` `{ ` ` ` `return` `(n * (n + 1) * (n + 2)) / 6; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main () ` ` ` `{ ` ` ` `int` `n = 5; ` ` ` ` ` `Console.WriteLine(tetrahedralNumber(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Ajit. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the ` `// nth tetrahedral number ` ` ` `function` `tetrahedralNumber(` `$n` `) ` `{ ` ` ` `return` `(` `$n` `* (` `$n` `+ 1) * (` `$n` `+ 2)) / 6; ` `} ` ` ` `// Driver Code ` ` ` `$n` `= 5; ` ` ` ` ` `echo` `tetrahedralNumber(` `$n` `); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

Output:

35

**Time Complexity**: O(1).

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program to print tetrahedral numbers upto Nth term
- Centered tetrahedral number
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Count numbers which can be constructed using two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Numbers less than N which are product of exactly two distinct prime numbers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Count numbers which are divisible by all the numbers from 2 to 10
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Find ratio of zeroes, positive numbers and negative numbers in the Array
- Check if a given pair of Numbers are Betrothed numbers or not
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Count of numbers upto M divisible by given Prime Numbers
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Ugly Numbers
- Count of Binary Digit numbers smaller than N

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.