# Heptagonal pyramidal number

Here given code implementation process.

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

void heptagonalPyramidalNo(int k)
{
// Print all initial k Heptagonal pyramidal number
for (int n = 0; n < k; ++n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth Heptagonal pyramidal number
int result = (n * (n + 1) * ((5 * n) - 2)) / 6;

// Display calculated result
printf("  %d", result);
}
}
int main()
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

// Test k = 10
heptagonalPyramidalNo(10);
return 0;
}``````

#### Output

``  0  1  8  26  60  115  196  308  456  645``
``````// Java program for
// Heptagonal pyramidal number
public class HeptagonalPyramidalNumber
{
public void heptagonalPyramidalNo(int k)
{
// Print all initial k Heptagonal pyramidal number
for (int n = 0; n < k; ++n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6
// Calculate nth Heptagonal pyramidal number
int result = (n * (n + 1) * ((5 * n) - 2)) / 6;
// Display calculated result
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc
// Test k = 10
}
}``````

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````// Include header file
#include <iostream>
using namespace std;

// C++ program for
// Heptagonal pyramidal number

class HeptagonalPyramidalNumber
{
public: void heptagonalPyramidalNo(int k)
{
// Print all initial k Heptagonal pyramidal number
for (int n = 0; n < k; ++n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth Heptagonal pyramidal number
int result = (n *(n + 1) *((5 *n) - 2)) / 6;

// Display calculated result
cout << " " << result;
}
}
};
int main()
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc
// Test k = 10
return 0;
}``````

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````package main
import "fmt"
// Go program for
// Heptagonal pyramidal number

func heptagonalPyramidalNo(k int) {
// Print all initial k heptagonal pyramidal number
for n := 0 ; n < k ; n++ {
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
var result int = (n * (n + 1) * ((5 * n) - 2)) / 6

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

// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

// Test k = 10
heptagonalPyramidalNo(10)
}``````

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````// Include namespace system
using System;
// Csharp program for
// Heptagonal pyramidal number
public class HeptagonalPyramidalNumber
{
public void heptagonalPyramidalNo(int k)
{
// Print all initial k Heptagonal pyramidal number
for (int n = 0; n < k; ++n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
int result = (n * (n + 1) * ((5 * n) - 2)) / 6;

// Display calculated result
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````<?php
// Php program for
// Heptagonal pyramidal number
class HeptagonalPyramidalNumber
{
public	function heptagonalPyramidalNo(\$k)
{
// Print all initial k Heptagonal pyramidal number
for (\$n = 0; \$n < \$k; ++\$n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth Heptagonal pyramidal number
\$result = (int)((\$n * (\$n + 1) * ((5 * \$n) - 2)) / 6);

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

function main()
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````// Node JS program for
// Heptagonal pyramidal number
class HeptagonalPyramidalNumber
{
heptagonalPyramidalNo(k)
{
// Print all initial k heptagonal pyramidal number
for (var n = 0; n < k; ++n)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
var result = parseInt((n * (n + 1) * ((5 * n) - 2)) / 6);

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

function main()
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````#  Python 3 program for
#  Heptagonal pyramidal number
class HeptagonalPyramidalNumber :
def heptagonalPyramidalNo(self, k) :
n = 0
#  Print all initial k heptagonal pyramidal number
while (n < k) :
#  Formula
#   n (n + 1) (5n - 2)
#   ———————————————————
#          6

#  Calculate nth heptagonal pyramidal number
result = int((n * (n + 1) * ((5 * n) - 2)) / 6)

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

def main() :
#  Heptagonal pyramidal number are
#  —————————————————————————————————————————————
#   0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
#  1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
#  5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
#  16758, 18676, 20735, 22940, 25296, 27808, 30481,
#  33320, 36330, 39516, 42883 ... etc

#  Test k = 10

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

#### Output

``  0  1  8  26  60  115  196  308  456  645``
``````#  Ruby program for
#  Heptagonal pyramidal number
class HeptagonalPyramidalNumber
def heptagonalPyramidalNo(k)
n = 0
#  Print all initial k heptagonal pyramidal number
while (n < k)
#  Formula
#   n (n + 1) (5n - 2)
#   ———————————————————
#          6

#  Calculate nth heptagonal pyramidal number
result = (n * (n + 1) * ((5 * n) - 2)) / 6

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

end

end

def main()
#  Heptagonal pyramidal number are
#  —————————————————————————————————————————————
#   0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
#  1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
#  5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
#  16758, 18676, 20735, 22940, 25296, 27808, 30481,
#  33320, 36330, 39516, 42883 ... etc

#  Test k = 10
end

main()``````

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````// Scala program for
// Heptagonal pyramidal number
class HeptagonalPyramidalNumber()
{
def heptagonalPyramidalNo(k: Int): Unit = {
var n: Int = 0;
// Print all initial k heptagonal pyramidal number
while (n < k)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
var result: Int = (n * (n + 1) * ((5 * n) - 2)) / 6;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: HeptagonalPyramidalNumber = new HeptagonalPyramidalNumber();
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

`` 0 1 8 26 60 115 196 308 456 645``
``````// Swift 4 program for
// Heptagonal pyramidal number
class HeptagonalPyramidalNumber
{
func heptagonalPyramidalNo(_ k: Int)
{
var n: Int = 0;
// Print all initial k heptagonal pyramidal number
while (n < k)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
let result: Int = (n * (n + 1) * ((5 * n) - 2)) / 6;

// Display calculated result
print(" ", result, terminator: "");
n += 1;
}
}
}
func main()
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

``  0  1  8  26  60  115  196  308  456  645``
``````// Kotlin program for
// Heptagonal pyramidal number
class HeptagonalPyramidalNumber
{
fun heptagonalPyramidalNo(k: Int): Unit
{
var n: Int = 0;
// Print all initial k heptagonal pyramidal number
while (n < k)
{
// Formula
//  n (n + 1) (5n - 2)
//  ———————————————————
//         6

// Calculate nth heptagonal pyramidal number
val result: Int = (n * (n + 1) * ((5 * n) - 2)) / 6;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
// Heptagonal pyramidal number are
// —————————————————————————————————————————————
//  0, 1, 8, 26, 60, 115, 196, 308, 456, 645, 880,
// 1166, 1508, 1911, 2380, 2920, 3536, 4233, 5016,
// 5890, 6860, 7931, 9108, 10396, 11800, 13325, 14976,
// 16758, 18676, 20735, 22940, 25296, 27808, 30481,
// 33320, 36330, 39516, 42883 ... etc

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

#### Output

`` 0 1 8 26 60 115 196 308 456 645``

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