Skip to content
Related Articles

Related Articles

Improve Article
Centered decagonal number
  • Last Updated : 09 Apr, 2021

Given a number n, find the nth Centered decagonal number . 
A Centered Decagonal Number is centered figurative number that represents a decagon with dot in center and all other dot surrounding it in successive decagonal form. Source[Wiki]
 

Center Decagonal number

The first few Centered Decagonal Numbers are : 
1, 11, 31, 61, 101, 151, 211, 281, 361, 451, 551, 661…………
Examples : 
 

Input :  3
Output : 31

Input : 6
Output : 151

 

In mathematics centered decagonal number for n-th term is given by : 
 



Cd_{n}= 5n^2+5n+1

Below is the basic implementation of the above idea.
 

C++




// Program to find nth
// centered decagonal
// number
#include <bits/stdc++.h>
using namespace std;
 
// Centered decagonal
// number function
 
int centereddecagonalnum(int n)
{
    // Formula to calculate nth
    // centered decagonal number &
    // return it into main function.
    return (5 * n * n + 5 * n + 1);
}
 
// Driver Code
int main()
{
    int n = 5;
    cout << n << "th centered decagonal"
                          << "number: ";
    cout << centereddecagonalnum(n);
    cout << endl;
    n = 9;
    cout << n << "th centered decagonal"
                          << "number: ";
    cout << centereddecagonalnum(n);
 
    return 0;
}

Java




// Java Program to find nth
// centered decagonal number
import java.io.*;
 
class GFG
{
     
    // Centered decagonal
    // number function
    static int centereddecagonalnum(int n)
    {
         
    // Formula to calculate nth
    // centered decagonal number &
    // return it into main function.
    return (5 * n * n + 5 * n + 1);
    }
 
    // Driver Code
    public static void main (String[] args)
    {
        int n = 5;
        System.out.print(n + "th centered " +
                       "decagonal number: ");
        System.out.println(centereddecagonalnum(n));
 
        n = 9;
        System.out.print(n + "th centered " +
                       "decagonal number: ");
        System.out.println(centereddecagonalnum(n));
    }
}
 
// This code is contributed by m_kit

Python3




# Program to find nth
# centered decagonal number
 
# Centered decagonal
# number function
def centereddecagonalnum(n) :
     
    # Formula to calculate
    # nth centered decagonal
    # number & return it
    # into main function.
    return (5 * n * n +
            5 * n + 1)
 
# Driver Code
if __name__ == '__main__' :
         
    n = 5
    print(n,"th centered decagonal " +
                          "number : ",
              centereddecagonalnum(n))
 
    n = 9
    print(n,"th centered decagonal " +
                          "number : ",
              centereddecagonalnum(n))
               
# This code is contributed by m_kit

C#




// Program to find nth
// centered decagonal
// number
using System;
 
class GFG
{
// Centered decagonal
// number function
static int centereddecagonalnum(int n)
{
    // Formula to calculate nth
    // centered decagonal number &
    // return it into main function.
    return (5 * n * n + 5 * n + 1);
}
 
// Driver Code
static public void Main ()
{
int n = 5;
Console.Write(n + "th centered decagonal"+
                              "number: ");
Console.WriteLine(centereddecagonalnum(n));
 
n = 9;
Console.Write(n + "th centered decagonal"+
                              "number: ");
Console.WriteLine(centereddecagonalnum(n));
}
}
 
// This code is contributed by aj_36

PHP




<?php
// Program to find nth
// centered decagonal number
 
// Centered decagonal
// number function
function centereddecagonalnum($n)
{
    // Formula to calculate
    // nth centered decagonal
    // number & return it
    // into main function.
    return (5 * $n * $n +
            5 * $n + 1);
}
 
// Driver Code
$n = 5;
echo $n , "th centered decagonal",
                       "number: ";
echo centereddecagonalnum($n);
echo "\n";
 
$n = 9;
echo $n , "th centered decagonal",
                       "number: ";
echo centereddecagonalnum($n);
 
// This code is contributed by ajit
?>

Javascript




<script>
 
// Javascript Program to find nth
// centered decagonal number
 
// Centered decagonal
// number function
function centereddecagonalnum(n)
{
     
    // Formula to calculate nth
    // centered decagonal number &
    // return it into main function.
    return (5 * n * n + 5 * n + 1);
}
 
// Driver Code
var n = 5;
document.write(n + "th centered " +
               "decagonal number: ");
document.write(centereddecagonalnum(n) + "<br>");
 
n = 9;
document.write(n + "th centered " +
               "decagonal number: ");
document.write(centereddecagonalnum(n));
 
// This code is contributed by Kirti
     
</script>

Output 

5th centered decagonalnumber: 151
9th centered decagonalnumber: 451

 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live




My Personal Notes arrow_drop_up
Recommended Articles
Page :