# Octahedral number

Here given code implementation process.

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

void octahedralNo(int k)
{
// Print all initial k octahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
int result = (n *(2 *(n *n) + 1)) / 3;

// Display calculated result
printf("  %d", result);
}
}
int main()
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

``  1  6  19  44  85  146  231  344  489  670``
``````// Java program for
// Octahedral number
public class OctahedralNumber
{
public void octahedralNo(int k)
{
// Print all initial k octahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
int result = (n * (2 * (n * n) + 1)) / 3;

// Display calculated result
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Octahedral number

class OctahedralNumber
{
public: void octahedralNo(int k)
{
// Print all initial k octahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
int result = (n *(2 *(n *n) + 1)) / 3;

// Display calculated result
cout << " " << result;
}
}
};
int main()
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````package main
import "fmt"
// Go program for
// Octahedral number

func octahedralNo(k int) {
// Print all initial k octahedral number
for n := 1 ; n <= k ; n++ {
// Formula
//   n(2n²+1)
//  —————————
//      3
// Calculate nth octahedral number
var result int = (n * (2 * (n * n) + 1)) / 3

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

//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````// Include namespace system
using System;

// Csharp program for
// Octahedral number

public class OctahedralNumber
{
public void octahedralNo(int k)
{
// Print all initial k octahedral number
for (int n = 1; n <= k; ++n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
int result = (n * (2 * (n * n) + 1)) / 3;

// Display calculated result
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````<?php
// Php program for
// Octahedral number
class OctahedralNumber
{
public	function octahedralNo(\$k)
{
// Print all initial k octahedral number
for (\$n = 1; \$n <= \$k; ++\$n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
\$result = (int)((\$n * (2 * (\$n * \$n) + 1)) / 3);

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

function main()
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.
// k = 10
}
main();``````

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````// Node JS program for
// Octahedral number
class OctahedralNumber
{
octahedralNo(k)
{
// Print all initial k octahedral number
for (var n = 1; n <= k; ++n)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
var result = parseInt((n * (2 * (n * n) + 1)) / 3);

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

function main()
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````#  Python 3 program for
#  Octahedral number
class OctahedralNumber :
def octahedralNo(self, k) :
n = 1
#  Print all initial k octahedral number
while (n <= k) :
#  Formula
#    n(2n²+1)
#   —————————
#      3

#  Calculate nth octahedral number
result = int((n * (2 * (n * n) + 1)) / 3)

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

def main() :
#   Octahedral number are
#  —————————————————————————————————————————————
#   1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
#   891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
#   4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
#   13131, 14644, 16269, 18010, 19871, 21856, 23969,
#   26214, 28595, 31116, 33781, 36594, 39559 etc.

#  k = 10

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

#### Output

``  1  6  19  44  85  146  231  344  489  670``
``````#  Ruby program for
#  Octahedral number
class OctahedralNumber
def octahedralNo(k)
n = 1
#  Print all initial k octahedral number
while (n <= k)
#  Formula
#    n(2n²+1)
#   —————————
#      3

#  Calculate nth octahedral number
result = (n * (2 * (n * n) + 1)) / 3

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

end

end

def main()
#   Octahedral number are
#  —————————————————————————————————————————————
#   1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
#   891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
#   4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
#   13131, 14644, 16269, 18010, 19871, 21856, 23969,
#   26214, 28595, 31116, 33781, 36594, 39559 etc.
#  k = 10
end

main()``````

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````// Scala program for
// Octahedral number
class OctahedralNumber()
{
def octahedralNo(k: Int): Unit = {
var n: Int = 1;
// Print all initial k octahedral number
while (n <= k)
{
// Formula

//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
var result: Int = (n * (2 * (n * n) + 1)) / 3;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: OctahedralNumber = new OctahedralNumber();
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.

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

#### Output

`` 1 6 19 44 85 146 231 344 489 670``
``````// Swift 4 program for
// Octahedral number
class OctahedralNumber
{
func octahedralNo(_ k: Int)
{
var n: Int = 1;
// Print all initial k octahedral number
while (n <= k)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
let result: Int = (n * (2 * (n * n) + 1)) / 3;

// Display calculated result
print(" ", result, terminator: "");

n += 1;
}
}
}
func main()
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.
// k = 10
}
main();``````

#### Output

``  1  6  19  44  85  146  231  344  489  670``
``````// Kotlin program for
// Octahedral number
class OctahedralNumber
{
fun octahedralNo(k: Int): Unit
{
var n: Int = 1;
// Print all initial k octahedral number
while (n <= k)
{
// Formula
//   n(2n²+1)
//  —————————
//     3

// Calculate nth octahedral number
val result: Int = (n * (2 * (n * n) + 1)) / 3;

// Display calculated result
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
//  Octahedral number are
// —————————————————————————————————————————————
//  1, 6, 19, 44, 85, 146, 231, 344, 489, 670,
//  891, 1156, 1469, 1834, 2255, 2736, 3281, 3894,
//  4579, 5340, 6181, 7106, 8119, 9224, 10425, 11726,
//  13131, 14644, 16269, 18010, 19871, 21856, 23969,
//  26214, 28595, 31116, 33781, 36594, 39559 etc.
// k = 10
}``````

#### Output

`` 1 6 19 44 85 146 231 344 489 670``

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