# Hexagonal number

Here given code implementation process.

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

void hexagonalNo(int k)
{
// Print all initial k Hexagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
int result = (2 *(n *n) - n);

// Display calculated result
printf("  %d", result);
}
}
int main()
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
hexagonalNo(10);
return 0;
}``````

#### Output

``  1  6  15  28  45  66  91  120  153  190``
``````// Java program for
// Heptagonal pyramidal number
public class HexagonalNumber
{
public void hexagonalNo(int k)
{
// Print all initial k Hexagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
int result = (2 * (n * n) - n);

// Display calculated result
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Heptagonal pyramidal number

class HexagonalNumber
{
public: void hexagonalNo(int k)
{
// Print all initial k Hexagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
int result = (2 *(n *n) - n);

// Display calculated result
cout << " " << result;
}
}
};
int main()
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
return 0;
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````package main
import "fmt"
// Go program for
// Heptagonal pyramidal number

func hexagonalNo(k int) {
// Print all initial k Hexagonal number
for n := 1 ; n <= k ; n++ {
// Formula
// (2n² -n)

// Calculate nth hexagonal number
var result int = (2 * (n * n) - n)

// Display calculated result
fmt.Print(" ", result)
}
}
func main() {

// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
hexagonalNo(10)
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````// Include namespace system
using System;
// Csharp program for
// Heptagonal pyramidal number
public class HexagonalNumber
{
public void hexagonalNo(int k)
{
// Print all initial k Hexagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
int result = (2 * (n * n) - n);

// Display calculated result
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````<?php
// Php program for
// Heptagonal pyramidal number
class HexagonalNumber
{
public	function hexagonalNo(\$k)
{
// Print all initial k Hexagonal number
for (\$n = 1; \$n <= \$k; ++\$n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
\$result = (2 * (\$n * \$n) - \$n);

// Display calculated result
echo(" ".\$result);
}
}
}

function main()
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
main();``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````// Node JS program for
// Heptagonal pyramidal number
class HexagonalNumber
{
hexagonalNo(k)
{
// Print all initial k Hexagonal number
for (var n = 1; n <= k; ++n)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
var result = (2 * (n * n) - n);

// Display calculated result
process.stdout.write(" " + result);
}
}
}

function main()
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
main();``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````#  Python 3 program for
#  Heptagonal pyramidal number
class HexagonalNumber :
def hexagonalNo(self, k) :
n = 1
#  Print all initial k Hexagonal number
while (n <= k) :
#  Formula
#  (2n² -n)

#  Calculate nth hexagonal number
result = (2 * (n * n) - n)

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

def main() :
#  Hexagonal number are
#  —————————————————————————————————————————————
#   1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
#   276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
#   946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
#   1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
#   3003, 3160, 3321, 3486, 3655, 3828 ... etc

#  k = 10

if __name__ == "__main__": main()``````

#### Output

``  1  6  15  28  45  66  91  120  153  190``
``````#  Ruby program for
#  Heptagonal pyramidal number
class HexagonalNumber
def hexagonalNo(k)
n = 1
#  Print all initial k Hexagonal number
while (n <= k)
#  Formula
#  (2n² -n)

#  Calculate nth hexagonal number
result = (2 * (n * n) - n)

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

end

end

def main()
#  Hexagonal number are
#  —————————————————————————————————————————————
#   1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
#   276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
#   946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
#   1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
#   3003, 3160, 3321, 3486, 3655, 3828 ... etc

#  k = 10
end

main()``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````// Scala program for
// Heptagonal pyramidal number
class HexagonalNumber()
{
def hexagonalNo(k: Int): Unit = {
var n: Int = 1;
// Print all initial k Hexagonal number
while (n <= k)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
var result: Int = (2 * (n * n) - n);

// Display calculated result
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: HexagonalNumber = new HexagonalNumber();
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``
``````// Swift 4 program for
// Heptagonal pyramidal number
class HexagonalNumber
{
func hexagonalNo(_ k: Int)
{
var n: Int = 1;
// Print all initial k Hexagonal number
while (n <= k)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
let result: Int = (2 * (n * n) - n);

// Display calculated result
print(" ", result, terminator: "");
n += 1;
}
}
}
func main()
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}
main();``````

#### Output

``  1  6  15  28  45  66  91  120  153  190``
``````// Kotlin program for
// Heptagonal pyramidal number
class HexagonalNumber
{
fun hexagonalNo(k: Int): Unit
{
var n: Int = 1;
// Print all initial k Hexagonal number
while (n <= k)
{
// Formula
// (2n² -n)

// Calculate nth hexagonal number
val result: Int = (2 * (n * n) - n);

// Display calculated result
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
// Hexagonal number are
// —————————————————————————————————————————————
//  1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231,
//  276, 325, 378, 435, 496, 561, 630, 703, 780, 861,
//  946, 1035, 1128, 1225, 1326, 1431, 1540, 1653, 1770,
//  1891, 2016, 2145, 2278, 2415, 2556, 2701, 2850,
//  3003, 3160, 3321, 3486, 3655, 3828 ... etc

// k = 10
}``````

#### Output

`` 1 6 15 28 45 66 91 120 153 190``

## Comment

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.