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++
// 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;
}
C
// C Program to find the
// nth Dodecagonal number
#include <stdio.h>
// 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;
printf("%d\n",Dodecagonal_number(n));
n = 12;
printf("%d\n",Dodecagonal_number(n));
return 0;
}
// This code is contributed by kothavvsaakash
Java
// 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
Python3
# 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.
C#
// 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
PHP
<?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
?>
JavaScript
<script>
// Javascript 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
let n = 7;
document.write(Dodecagonal_number(n) + "<br>");
n = 12;
document.write(Dodecagonal_number(n) + "<br>");
// This code is contributed by subham348.
</script>
Time Complexity: O(1)
Auxiliary Space: O(1)
References: https://en.wikipedia.org/wiki/Dodecagonal_number
Similar Reads
Hendecagonal number Given a number n, the task is to find the nth Hendecagonal number. A Hendecagonal number is a figurate number that extends the concept of triangular and square numbers to the decagon (Eleven -sided polygon). The nth hendecagonal number counts the number of dots in a pattern of n nested decagons, all
4 min read
Hexadecagonal number Given a number n, the task is to find the nth hexadecagonal number. A Hexadecagonal number is class of figurate number and a perfect squares. It has sixteen sided polygon called hexadecagon or hexakaidecagon. The n-th hexadecagonal number count's the sixteen number of dots and all others dots are su
4 min read
Enneadecagonal number Given a number n, the task is to find the nth Enneadecagonal number. An Enneadecagonal number is a nineteen-sided polygon in mathematics. It belongs to a class of figurative numbers. The number contains the number of dots and the dots are arranged in a pattern or series. An Enneadecagonal number is
3 min read
Heptadecagonal number Given a number n, the task is to find the nth heptadecagonal number . A heptadecagonal number is a class of figurate numbers. It has a seventeen-sided polygon called heptadecagon. The n-th heptadecagonal number countâs the seventeen number of dots and all other dots are surrounding with a common sha
4 min read
Nonagonal number A nonagonal number is a figurate number that extends the concept of triangular and square numbers to the nonagon. Specifically, the nth nonagonal numbers count the number of dots in a pattern of n nested nonagons (9 sided polygons), all sharing a common corner, where the ith nonagon in the pattern h
5 min read
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 Mathemat
4 min read