Dodecagonal number

Given a number n, find the nth Dodecagonal number.Dodecagonal numbers represent Dodecagonal (A polygon with 12 sides).

Some of the Dodecagonal numbers are:
1, 12, 33, 64, 105, 156, 217, 288, 369, 460, 561, 672, 793, 924………………………..

Examples :



Input : n = 4
Output : 64

Input : n = 9
Output : 369

Formula of nth Term of Dodecagonal number :

n-th Dodecagonal number = 5n2 - 4n

Below is the implementation for nth Dodecagonal Number:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP Program to find the
// nth Dodecagonal number
#include <bits/stdc++.h>
using namespace std;
  
// function for Dodecagonal
// number
int Dodecagonal_number(int n)
{
    // formula for find Dodecagonal
    // nth term
    return 5 * n * n - 4 * n;
}
  
// Driver Code
int main()
{
  
    int n = 7;
    cout << Dodecagonal_number(n) << endl;
  
    n = 12;
    cout << Dodecagonal_number(n) << endl;
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find the 
// nth Dodecagonal number
import java.util.*;
  
class GFG 
{
  
    // function for 
    // Dodecagonal number
    static int Dodecagonal_number(int n)
    {
        // formula for find 
        // Dodecagonal nth term
        return 5 * n * n - 4 * n;
    }
      
    // Driver Code
    public static void main(String[] args) 
    {
  
    int n = 7;
    System.out.println(Dodecagonal_number(n));
  
    n = 12;
    System.out.println(Dodecagonal_number(n));
  
    }
}
  
// This code is contributed by Anuj_67

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to find
# nth Dodecagonal number
  
# Function to calculate
# Dodecagonal number
def Dodecagonal_number(n):
  
    # Formula to calculate nth
    # Dodecagonal number
      
    return  5 * n * n - 4 * n
  
# Driver Code
n = 7
print(Dodecagonal_number(n))
  
n = 12
print(Dodecagonal_number(n))
                      
# This code is contributed by aj_36.

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find the nth Dodecagonal
// number
using System;
  
class GFG {
  
    // function for Dodecagonal
    // number
    static int Dodecagonal_number(int n)
    {
        // formula for find Dodecagonal
        // nth term
        return 5 * n * n - 4 * n;
    }
      
    // Driver Code
    static void Main()
    {
      
        int n = 7;
        Console.WriteLine(Dodecagonal_number(n));
      
        n = 12;
        Console.WriteLine(Dodecagonal_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 Dodecagonal number
  
// function for Dodecagonal
// number
function Dodecagonal_number($n)
{
      
    // formula for find Dodecagonal
    // nth term
    return 5 * $n * $n - 4 * $n;
}
  
// Driver code
    $n = 7;
    echo Dodecagonal_number($n), "\n";
  
    $n = 12;
    echo Dodecagonal_number($n), "\n";
  
      
// This code is contributed by aj_36
?>

chevron_right


Output :

217
672

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.