Decagonal Numbers - GeeksforGeeks

13 Jul, 2021
You are given a number n, the task is to find the nth Decagonal number. A decagonal number is a figurate number that extends the concept of triangular and square numbers to the decagon (a ten-sided polygon). The nth decagonal numbers counts the number of dots in a pattern of n nested decagons, all sharing a common corner, where the ith decagon in the pattern has sides made of i dots spaced one unit apart from each other.
Examples: 
Input : n = 3
Output : 27

Input : n = 7
Output : 175
 
The n-th decagonal number is given by the formula (4n 2 – 3n). 
C++
Java
Python
C#
PHP
Javascript
// C++ program to find nth decagonal number#include <bits/stdc++.h>using namespace std;  // Function to calculate decagonal numberint decagonal(int n){    // Formula for finding nth decagonal number    return 4 * n * n - 3 * n;}  // Driver functionint main(){    int n = 10;    cout << n << "th decagonal number :" << decagonal(n);    return 0;}
// JAVA Code for Decagonal Numbersimport java.util.*; class GFG {     // Function to calculate    // decagonal number    static int decagonal(int n)    {        // Formula for finding nth        // decagonal number        return 4 * n * n - 3 * n;    }         /* Driver function */    public static void main(String[] args)    {           int n = 10;        System.out.println(n + "th decagonal number :"                            + decagonal(n));    }} // This code is contributed by Arnav Kr. Mandal.
# Python program to find nth decagonal numberdef decagonal(n):    return 4 * n * n - 3 * n  # Driver coden = 10print(n, "th decagonal number :", decagonal(n))
// C# Code for Decagonal Numbersusing System; class GFG {     // Function to calculate    // decagonal number    static int decagonal(int n)    {        // Formula for finding nth        // decagonal number        return 4 * n * n - 3 * n;    }         // Driver Code    public static void Main()    {        int n = 10;        Console.Write(n + "th decagonal number : "                                   + decagonal(n));    }} // This code is contributed by vt_m.
<?php// PHP program to find nth// decagonal number // Function to calculate// decagonal numberfunction decagonal($n){         // Formula for finding nth    // decagonal number    return 4 * $n * $n - 3 * $n;} // Driver function$n = 10;echo $n, "th decagonal number :",                 decagonal($n); // This code is contributed by ajit?>
<script> // JavaScript program for Decagonal Numbers // Function to calculate// decagonal numberfunction decagonal(n){         // Formula for finding nth    // decagonal number    return 4 * n * n - 3 * n;} // Driver codelet n = 10;document.write(n + "th decagonal number : " +               decagonal(n));                // This code is contributed by souravghosh0416 </script>
Output: 
10th decagonal number : 370
Time Complexity: O(1)Auxiliary Space: O(1) 
jit_t
souravghosh0416
manikarora059
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Find all factors of a natural number | Set 1
Check if a number is Palindrome
Program to print prime numbers from 1 to N.
Program to add two binary strings
Fizz Buzz Implementation
Program to multiply two matrices
Find pair with maximum GCD in an array
Find Union and Intersection of two unsorted arrays
Count all possible paths from top left to bottom right of a mXn matrix
Count ways to reach the n'th stair