Decagonal Numbers

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++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find nth decagonal number
#include <bits/stdc++.h>
using namespace std;
   
// Function to calculate decagonal number
int decagonal(int n)
{
    // Formula for finding nth decagonal number
    return 4 * n * n - 3 * n;
}
   
// Driver function
int main()
{
    int n = 10;
    cout << n << "th decagonal number :" << decagonal(n);
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// JAVA Code for Decagonal Numbers
import 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.

chevron_right


Python

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to find nth decagonal number
def decagonal(n):
    return 4 * n * n - 3 * n
   
# Driver code
n = 10
print(n, "th decagonal number :", decagonal(n))

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Code for Decagonal Numbers
using 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.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to find nth
// decagonal number
  
// Function to calculate
// decagonal number
function 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
?>

chevron_right



Output:

10th decagonal number : 370


My Personal Notes arrow_drop_up


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 : 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.