Open In App

Dodecagonal number

Last Updated : 18 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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>


Output : 

217
672

 

Time Complexity: O(1)
Auxiliary Space: O(1)
References: https://en.wikipedia.org/wiki/Dodecagonal_number
 



Similar Reads

Centered Dodecagonal Number
Given a number n, find the nth Centered Dodecagonal Number. The Centered Dodecagonal Number represents a dot in the center and other dots surrounding it in successive dodecagonal(12 sided polygon) layers. Examples : Input : 3 Output : 37 Input : 7 Output :253 The first few centered dodecagonal numbers are: 1, 13, 37, 73, 121, 181, 253, 337, 433, 54
3 min read
Program to check if N is a Centered dodecagonal number
Given an integer N, the task is to check if N is a Centered Dodecagonal Number or not. If the number N is a Centered Dodecagonal Number then print "Yes" else print "No". Centered Dodecagonal Number represents a dot in the center and other dots surrounding it in successive Dodecagonal Number(12 sided polygon) layers. The first few Centered Dodecagon
4 min read
Program to check if N is a Dodecagonal Number
Given a number N, the task is to check if N is a Dodecagonal Number or not. If the number N is a Dodecagonal Number then print "Yes" else print "No". dodecagonal number represent Dodecagonal(12 sides polygon).The first few dodecagonal numbers are 1, 12, 33, 64, 105, 156, 217... Examples: Input: N = 12 Output: Yes Explanation: Second dodecagonal num
4 min read
Find the sum of the first N Centered Dodecagonal Number
Given a number N, the task is to find the sum of first N Centered Dodecagonal Number. The first few Centered Dodecagonal Numbers are 1, 13, 37, 73, 121, 181 ... Examples: Input: N = 3 Output: 51 Explanation: 1, 13 and 37 are the first three centered Dodecagonal number.Input: N = 5 Output: 245 Approach: Initially, create a function which will help u
4 min read
Find the sum of the first N Dodecagonal Numbers
Given a number N the task is to find the sum of first N Dodecagonal Number. The first few dodecagonal numbers are 1, 12, 33, 64, 105, 156, 217 ... Examples: Input: N = 3 Output: 46 Explanation: 1, 12 and 33 are the first three Dodecagonal numbers Input: N = 5 Output: 215 Approach: Initially, we need to create a function that will help us to calcula
4 min read
Check Whether a Number is an Anti Prime Number(Highly Composite Number)
Given a positive integer N, the task is to tell whether it's an anti-prime number or not. Anti-Prime Numbers (Highly Composite Number): A positive integer that has more divisors than any positive number smaller than it, is called an Anti-Prime Number (also known as Highly Composite Number). Following is the list of the first 10 anti-prime numbers a
5 min read
Number of factors of very large number N modulo M where M is any prime number
Given a large number N, the task is to find the total number of factors of the number N modulo M where M is any prime number. Examples: Input: N = 9699690, M = 17 Output: 1 Explanation: Total Number of factors of 9699690 is 256 and (256 % 17) = 1Input: N = 193748576239475639, M = 9 Output: 8 Explanation: Total Number of factors of 9699690 is 256 an
8 min read
Permutation of a number whose sum with the original number is equal to another given number
Given two integers A and C, the task is to check if there exists a permutation of the number A such that the sum of the number A and its permutation is equal to C. Examples: Input: A = 133, C = 446Output: YesExplanation: One of the permutation of A is 313. Therefore, sum = 133 + 313 = 446, which is equal to C. Input: A = 200, C = 201Output: No Naiv
6 min read
Minimum number of moves to make M and N equal by repeatedly adding any divisor of number to itself except 1 and the number
Given two numbers N and M, the task is to find the minimum number of moves to change N to M or -1 if it's impossible. In one move, add to the current number any of its divisors not equal to 1 and the number itself. Examples: Input: N = 4, M = 24Output: 5Explanation: the number 24 can be reached starting from 4 using 5 operations: 4-&gt;6-&gt;8-&gt;
16 min read
Given a number as a string, find the number of contiguous subsequences which recursively add up to 9
Given a number as a string, write a function to find the number of substrings (or contiguous subsequences) of the given string which recursively add up to 9. Example: Digits of 729 recursively add to 9, 7 + 2 + 9 = 18 Recur for 18 1 + 8 = 9 Examples: Input: 4189 Output: 3 There are three substrings which recursively add to 9. The substrings are 18,
6 min read
Article Tags :
Practice Tags :