Centered Pentagonal Number


What do you understand by a centered pentagonal number? Let’s decode in this article.

First of all, what is a pentagon? You must be aware of this term. To recall, A pentagon is a geometric shape with five straight sides and five angles that is two−dimensional. The Greek terms "penta," which means "five," and "gonia," which means "angle," are the origin of the word "pentagon."

All of the sides and angles make up a regular pentagon (equal in measure). The sum of all the angles of a regular pentagon, which has 108 degrees for each angle, is 540 degrees.

Pentagon shapes can be seen in a variety of settings, including the shape of some structures and monuments and the structure of some molecules. Moreover, they are employed in a variety of games and puzzles, including the pentominoes game, which entails arranging a number of pentagon−shaped tiles to create a larger shape.

What is a Pentagonal Number?

The number of dots that can be placed in a regular pentagon pattern is represented by a figurative number called a pentagonal number. It is a number that may be expressed as the sum of all successive odd integers beginning with 1, where the number of odd integers utilized in the sum corresponds to the pentagonal number's index.

For example, the first few pentagonal numbers are 1,5,12,22,...

The formula for calculating the nth pentagonal number is n(3n−1)/2.

What is a Centered Pentagonal Number?

One way to think of a centered pentagonal number is as a pentagon with a dot in the middle and concentric rings of dots surrounding the dot, creating a star−like pattern.

A regular pentagonal number is used to create a centered pentagonal number by adding a single dot to the pentagon's center.

The first few centered pentagonal numbers are 1,6,16,31,....

The formula for calculating the nth−centered pentagonal number is (5n^2 − 5n + 2)/2.

Approach

Now, we know the logic which goes into calculating the centered pentagonal number. Let’s write the stepwise approach for the program.

  • Specify the value of n, you can also take this as user input.

  • Use the formula (5n^2 − 5n + 2)/2 to calculate the nth−centered pentagonal number.

  • Print your calculation to the console.

C++ Code Implementation

Too much theory? Let’s get into code mode. Here is the c++ code implementation to calculate the centered pentagonal number.

#include <iostream>

using namespace std;

int centeredPentagonal(int n) {
    return (5*n*n - 5*n + 2)/2;
}

int main() {
    int limit= 9;
        cout << limit<<"th centered pentagonal number is :"<<centeredPentagonal(limit);
    

    return 0;
}

Output

9th centered pentagonal number is:181

Time Complexity: O(1)

Space Complexity: O(1)

Conclusion

In this article, we have covered what is a centered pentagonal number and also the logic for writing c++ code for the same. Hope you have a clear idea of the concept.

Updated on: 23-Aug-2023

126 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements