- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Centered Tetrahedral Number
What do you understand by a centered tetrahedral number? Let’s explore it in this article.
Firstly, what is a tetrahedral number?
A tetrahedral number is a figurate number that represents the number of spheres in a tetrahedron. It is also known as a triangular pyramid number. A tetrahedron is a three−dimensional geometric shape that has four triangular faces, six edges, and four vertices.
To find the nth tetrahedral number, you can use the formula:
Tn = (n * (n + 1) * (n + 2)) / 6
For example, the first few tetrahedral numbers are: 1,4,10,20,35,56,84
Look at the diagram below to have a clear understanding of tetrahedral numbers. Here we have A pyramid with a sides length of 5 containing 35 spheres. Each layer represents one of the first five triangular numbers.
Now, what is a centered tetrahedral number?
A centered tetrahedral number is a type of figurate number that represents the number of spheres needed to create a centered tetrahedron of a given size. A centered tetrahedron is a three−dimensional geometric shape that has a tetrahedron inside an octahedron, with one sphere at the center of each face.
The formula to find the nth−centered tetrahedral number is:
CTn = ((2n+1)(n^2+n+3))/3
Some of the initial centered tetrahedral numbers are 1, 5, 15, 35, 69, ….
Approach
Now, let’s convert the logic discussed above into a stepwise approach we will use in our code implementation.
Specify the value of n, this can also be taken as user input.
Use the formula CTn = ((2n+1)(n^2+n+3))/3 to calculate the nth−centered tetrahedral number.
Print the calculation to the console.
C++ Code Implementation
Too much theory? Let’s get straight to code. Here is the c++ code implementation to calculate the nth−centered tetrahedral number.
Example
#include <iostream> using namespace std; int centeredTetrahedralNumber(int n) { return ((2*n+1)*(n*n+n+3))/3; } int main() { int n=9; cout << "The " << n << "th centered tetrahedral number is: " << centeredTetrahedralNumber(n) << endl; return 0; }
Output
The 9th centered tetrahedral number is: 589
Time Complexity: O(1)
Space Complexity: O(1)
Conclusion
In this article, we have covered what is a tetrahedral number, also what is centered tetrahedral number. In addition, we also covered the logic to calculate an nth−centered tetrahedral number and its c++ code implementation. Hope you found the article helpful.