Dodecahedral number

Given a number n, the task is to find n-th dodecahedral number.
A dodecahedral number belongs to a figurate number and represents it dodecahedron.

First few Dodecahedral number (where n = 0, 1, 2, 3…….) are : 0, 1, 20, 84 and so on.

Examples :

Input : 2
Output : 20

Input :8
Output :2024

Mathematics formula for nth dodecahedral number:

  \begin{math}D_{n}=n(3n-1)(3n-2)/2  

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find nth
// dodecahedral number
#include <bits/stdc++.h>
using namespace std;
  
// Function to find
// dodecahedral number
int dodecahedral_num(int n)
{
    // Formula to calculate nth
    // dodecahedral number
    // and return it into main function.
    return n * (3 * n - 1) * (3 * n - 2) / 2;
}
  
// Driver Code
int main()
{
    int n = 5;
    // print result
    cout << n << "th Dodecahedral number: ";
    cout << dodecahedral_num(n);
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find nth dodecahedral 
// number
import java.io.*;
  
class GFG {
  
    // Function to find dodecahedral number
    static int dodecahedral_num(int n)
    {
          
        // Formula to calculate nth
        // dodecahedral number
        // and return it into main function.
        return n * (3 * n - 1) *
                           (3 * n - 2) / 2;
    }
      
    // Driver Code
    public static void main (String[] args)
    {
        int n = 5;
        // print result
        System.out.print( n + "the Dodecahedral"
                                  + " number:");
        System.out.println( dodecahedral_num(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 dodecahedral number
  
# Function to calculate
# dodecahedral number
  
def dodecahedral_num(n):
  
    # Formula to calculate nth
    # dodecahedral number
      
    return n * (3 * n - 1) * (3 * n - 2) // 2
  
# Driver Code
n = 5
print("%sth Dodecahedral number :" %n,
                    dodecahedral_num(n))
                      
# This code is contributed by ajit.                 

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find nth dodecahedral 
// number
using System;
  
class GFG {
  
    // Function to find dodecahedral number
    static int dodecahedral_num(int n)
    {
          
        // Formula to calculate nth
        // dodecahedral number
        // and return it into main function.
        return n * (3 * n - 1) *
                        (3 * n - 2) / 2;
    }
      
    // Driver Code
    public static void Main ()
    {
        int n = 5;
  
        // print result
        Console.Write( n + "the Dodecahedral"
                                + " number:");
        Console.WriteLine( dodecahedral_num(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 nth
// dodecahedral number
  
  
// Function to find
// dodecahedral number
function dodecahedral_num( $n)
{
    // Formula to calculate nth
    // dodecahedral number
    // and return it into main function.
    return $n * (3 * $n - 1) * 
                (3 * $n - 2) / 2;
}
  
// Drivers Code
$n = 5;
  
// print result
echo $n, "th Dodecahedral number: ";
echo dodecahedral_num($n);
  
// This code is contributed by vt_m
?>

chevron_right


Output :

5th Dodecahedral number: 455

Reference: https://en.wikipedia.org/wiki/Dodecahedral_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.