Decagonal number

Here given code implementation process.

// C Program for
// Decagonal number
#include <stdio.h>

void decagonalNo(int k)
{
    // Print all initial k decagonal number
    for (int n = 0; n < k; ++n)
    {
        // Formula
        //  (4n² - 3n )
        // Calculate nth decagonal number
        int result = (4 *(n *n) - 3 *n);
        // Display Calculated value
        printf("  %d", result);
    }
}
int main()
{
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    decagonalNo(10);
    return 0;
}

Output

 0 1 10 27 52 85 126 175 232 297
// Java program for
// Decagonal number
public class DecagonalNumber
{
    public void decagonalNo(int k)
    {
        // Print all initial k decagonal number
        for (int n = 0; n < k; ++n)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            int result = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            System.out.print(" " + result);
        }
    }
    public static void main(String[] args)
    {
        DecagonalNumber task = new DecagonalNumber();
        // Decagonal number are
        // —————————————————————————————————————————————
        // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
        // 451, 540, 637, 742, 855, 976, 1105, 1242, 
        // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
        // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
        // 4522, 4795, 5076, 5365, 5662 ... etc
      
        // Test k = 10
        task.decagonalNo(10);
    }
}

Output

 0 1 10 27 52 85 126 175 232 297
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Decagonal number

class DecagonalNumber
{
    public: void decagonalNo(int k)
    {
        // Print all initial k decagonal number
        for (int n = 0; n < k; ++n)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            int result = (4 *(n *n) - 3 *n);
          
            // Display calculated result
            cout << " " << result;
        }
    }
};
int main()
{
    DecagonalNumber *task = new DecagonalNumber();
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    task->decagonalNo(10);
    return 0;
}

Output

 0 1 10 27 52 85 126 175 232 297
// Include namespace system
using System;
// Csharp program for
// Decagonal number
public class DecagonalNumber
{
    public void decagonalNo(int k)
    {
        // Print all initial k decagonal number
        for (int n = 0; n < k; ++n)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            int result = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            Console.Write(" " + result);
        }
    }
    public static void Main(String[] args)
    {
        DecagonalNumber task = new DecagonalNumber();
        // Decagonal number are
        // —————————————————————————————————————————————
        // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
        // 451, 540, 637, 742, 855, 976, 1105, 1242, 
        // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
        // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
        // 4522, 4795, 5076, 5365, 5662 ... etc
      
        // Test k = 10
        task.decagonalNo(10);
    }
}

Output

 0 1 10 27 52 85 126 175 232 297
package main
import "fmt"
// Go program for
// Decagonal number

func decagonalNo(k int) {
    // Print all initial k decagonal number
    for n := 0 ; n < k ; n++ {
        // Formula
        //  (4n² - 3n )
        // Calculate nth decagonal number
        var result int = (4 * (n * n) - 3 * n)
        // Display calculated result
        fmt.Print(" ", result)
    }
}
func main() {

    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
    // Test k = 10
    decagonalNo(10)
}

Output

 0 1 10 27 52 85 126 175 232 297
<?php
// Php program for
// Decagonal number
class DecagonalNumber
{
    public  function decagonalNo($k)
    {
        // Print all initial k decagonal number
        for ($n = 0; $n < $k; ++$n)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            $result = (4 * ($n * $n) - 3 * $n);
          
            // Display calculated result
            echo(" ".$result);
        }
    }
}

function main()
{
    $task = new DecagonalNumber();
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    $task->decagonalNo(10);
}
main();

Output

 0 1 10 27 52 85 126 175 232 297
// Node JS program for
// Decagonal number
class DecagonalNumber
{
    decagonalNo(k)
    {
        // Print all initial k decagonal number
        for (var n = 0; n < k; ++n)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            var result = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            process.stdout.write(" " + result);
        }
    }
}

function main()
{
    var task = new DecagonalNumber();
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    task.decagonalNo(10);
}
main();

Output

 0 1 10 27 52 85 126 175 232 297
#  Python 3 program for
#  Decagonal number
class DecagonalNumber :
    def decagonalNo(self, k) :
        n = 0
        #  Print all initial k decagonal number
        while (n < k) :
            #  Formula
            #   (4n² - 3n )
            
            #  Calculate nth decagonal number
            result = (4 * (n * n) - 3 * n)

            #  Display calculated result
            print(" ", result, end = "")
            n += 1
        
    

def main() :
    task = DecagonalNumber()
    #  Decagonal number are
    #  —————————————————————————————————————————————
    #  0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    #  451, 540, 637, 742, 855, 976, 1105, 1242, 
    #  1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    #  2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    #  4522, 4795, 5076, 5365, 5662 ... etc
    
    #  Test k = 10
    task.decagonalNo(10)

if __name__ == "__main__": main()

Output

  0  1  10  27  52  85  126  175  232  297
#  Ruby program for
#  Decagonal number
class DecagonalNumber 
    def decagonalNo(k) 
        n = 0
        #  Print all initial k decagonal number
        while (n < k) 
            #  Formula
            #   (4n² - 3n )
            
            #  Calculate nth decagonal number
            result = (4 * (n * n) - 3 * n)

            #  Display calculated result
            print(" ", result)
            n += 1
        end

    end

end

def main() 
    task = DecagonalNumber.new()
    #  Decagonal number are
    #  —————————————————————————————————————————————
    #  0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    #  451, 540, 637, 742, 855, 976, 1105, 1242, 
    #  1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    #  2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    #  4522, 4795, 5076, 5365, 5662 ... etc
    
    #  Test k = 10
    task.decagonalNo(10)
end

main()

Output

 0 1 10 27 52 85 126 175 232 297
// Scala program for
// Decagonal number
class DecagonalNumber()
{
    def decagonalNo(k: Int): Unit = {
        var n: Int = 0;
        // Print all initial k decagonal number
        while (n < k)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            var result: Int = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            print(" " + result);
            n += 1;
        }
    }
}
object Main
{
    def main(args: Array[String]): Unit = {
        var task: DecagonalNumber = new DecagonalNumber();
        // Decagonal number are
        // —————————————————————————————————————————————
        // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
        // 451, 540, 637, 742, 855, 976, 1105, 1242, 
        // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
        // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
        // 4522, 4795, 5076, 5365, 5662 ... etc
  
        // Test k = 10
        task.decagonalNo(10);
    }
}

Output

 0 1 10 27 52 85 126 175 232 297
// Swift 4 program for
// Decagonal number
class DecagonalNumber
{
    func decagonalNo(_ k: Int)
    {
        var n: Int = 0;
        // Print all initial k decagonal number
        while (n < k)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            let result: Int = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            print(" ", result, terminator: "");
            n += 1;
        }
    }
}
func main()
{
    let task: DecagonalNumber = DecagonalNumber();
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    task.decagonalNo(10);
}
main();

Output

  0  1  10  27  52  85  126  175  232  297
// Kotlin program for
// Decagonal number
class DecagonalNumber
{
    fun decagonalNo(k: Int): Unit
    {
        var n: Int = 0;
        // Print all initial k decagonal number
        while (n < k)
        {
            // Formula
            //  (4n² - 3n )
          
            // Calculate nth decagonal number
            val result: Int = (4 * (n * n) - 3 * n);
          
            // Display calculated result
            print(" " + result);
            n += 1;
        }
    }
}
fun main(args: Array < String > ): Unit
{
    val task: DecagonalNumber = DecagonalNumber();
    // Decagonal number are
    // —————————————————————————————————————————————
    // 0, 1, 10, 27, 52, 85, 126, 175, 232, 297, 370, 
    // 451, 540, 637, 742, 855, 976, 1105, 1242, 
    // 1387, 1540, 1701, 1870, 2047, 2232, 2425, 2626, 
    // 2835, 3052, 3277, 3510, 3751, 4000, 4257, 
    // 4522, 4795, 5076, 5365, 5662 ... etc
  
    // Test k = 10
    task.decagonalNo(10);
}

Output

 0 1 10 27 52 85 126 175 232 297


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved