Dodecagonal Number


What do you understand by the Dodecagonal number?

In order to understand the Dodecagonal number, we first need to understand a dodecagon.

What is a Dodecagon?

A polygon with twelve sides and twelve angles is called a dodecagon. It is a two−dimensional geometric shape that may be created by joining twelve line segments, each of which forms a closed loop when it connects with two other segments. Every side and angle of a normal dodecagon are equal to one another. A dodecagon's interior angles add up to 180(n−2) degrees, where n is the number of sides. As a result, a dodecagon's angles total 1800 degrees.

A figurate number that represents a dodecagon is known as a Dodecagonal number.

We need to calculate the nth Dodecagonal number for a given value of n. The formula to calculate the Dodecagonal number is

D(n) = 5n^2 − 4n

The series of Decagonal numbers include 0, 1, 12, 33, 64, 105, 156, ….

Approach

Let’s see the step−by−step implementation to calculate the nth Dodecagonal number.

  • Take the value of n as input

  • Use the formula discussed above to calculate the nth Dodecagonal number.

  • Print the value to the console

Code Implementation

Having discussed the theory, let’s jump to the code. Here is the C++ code to calculate the nth Decagonal Number for the given value of n

Example

#include <iostream>

using namespace std;

int dodecagonal_number(int n) {
    return 5*n*n - 4*n;
}

int main() {
    int n = 12;
    
    int result = dodecagonal_number(n);
    cout << "The " << n << "th dodecagonal number is " << result << endl;
    return 0;
}

Output

The 12th dodecagonal number is 672

Time Complexity: O(1)

Space Complexity: O(1)

Conclusion

In this article, we have covered what is the decagonal number, and the approach along with code implementation to calculate the nth Dodecagonal number. Hope you are able to understand the concept in a better way.

Updated on: 23-Aug-2023

55 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements