Centered octahedral number
Here given code implementation process.
// C Program for
// Centered octahedral number
#include <stdio.h>
void centeredOctahedralNo(int k)
{
// Print all initial k centered octahedral number
for (int n = 0; n < k; ++n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
int result = (((2 * n) + 1) *(2 * (n * n) + (2 * n) + 3)) / 3;
// Display Calculated value
printf(" %d", result);
}
}
int main()
{
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
centeredOctahedralNo(10);
return 0;
}
Output
1 7 25 63 129 231 377 575 833 1159
// Java program for
// Centered octahedral number
public class CenteredOctahedral
{
public void centeredOctahedralNo(int k)
{
// Print all initial k centered octahedral number
for (int n = 0; n < k; ++n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
int result = (((2 * n) + 1) * (2 * (n * n) + (2 * n) + 3)) / 3;
// Display Calculated value
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
CenteredOctahedral task = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
}
Output
1 7 25 63 129 231 377 575 833 1159
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered octahedral number
class CenteredOctahedral
{
public: void centeredOctahedralNo(int k)
{
// Print all initial k centered octahedral number
for (int n = 0; n < k; ++n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
int result = (((2 *n) + 1) *(2 *(n *n) + (2 *n) + 3)) / 3;
// Display Calculated value
cout << " " << result;
}
}
};
int main()
{
CenteredOctahedral *task = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task->centeredOctahedralNo(10);
return 0;
}
Output
1 7 25 63 129 231 377 575 833 1159
// Include namespace system
using System;
// Csharp program for
// Centered octahedral number
public class CenteredOctahedral
{
public void centeredOctahedralNo(int k)
{
// Print all initial k centered octahedral number
for (int n = 0; n < k; ++n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
int result = (((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3;
// Display Calculated value
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
CenteredOctahedral task = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
}
Output
1 7 25 63 129 231 377 575 833 1159
package main
import "fmt"
// Go program for
// Centered octahedral number
func centeredOctahedralNo(k int) {
// Print all initial k centered octahedral number
for n := 0 ; n < k ; n++ {
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
var result int = (((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3
// Display Calculated value
fmt.Print(" ", result)
}
}
func main() {
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
centeredOctahedralNo(10)
}
Output
1 7 25 63 129 231 377 575 833 1159
<?php
// Php program for
// Centered octahedral number
class CenteredOctahedral
{
public function centeredOctahedralNo($k)
{
// Print all initial k centered octahedral number
for ($n = 0; $n < $k; ++$n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
$result = (int)((((2 * $n) + 1) *
(2 * ($n * $n) +
(2 * $n) + 3)) / 3);
// Display Calculated value
echo(" ".$result);
}
}
}
function main()
{
$task = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
$task->centeredOctahedralNo(10);
}
main();
Output
1 7 25 63 129 231 377 575 833 1159
// Node JS program for
// Centered octahedral number
class CenteredOctahedral
{
centeredOctahedralNo(k)
{
// Print all initial k centered octahedral number
for (var n = 0; n < k; ++n)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
var result = parseInt((((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3);
// Display Calculated value
process.stdout.write(" " + result);
}
}
}
function main()
{
var task = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
main();
Output
1 7 25 63 129 231 377 575 833 1159
# Python 3 program for
# Centered octahedral number
class CenteredOctahedral :
def centeredOctahedralNo(self, k) :
n = 0
# Print all initial k centered octahedral number
while (n < k) :
# Formula
# (2n+1) (2n² + 2n + 3)
# ——————————————————————
# 3
# Calculate nth octahedral number
result = int((((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3)
# Display Calculated value
print(" ", result, end = "")
n += 1
def main() :
task = CenteredOctahedral()
# Centered octahedral numbers are
# —————————————————————————————————————————————
# 1, 7, 25, 63, 129, 231, 377, 575, 833,
# 1159, 1561, 2047, 2625, 3303, 4089, 4991,
# 6017, 7175, 8473, 9919, 11521, 13287, 15225,
# 17343, 19649, 22151, 24857, 27775, 30913,
# 34279, 37881, 41727, 45825, 50183, 54809 ... etc
# Test k = 10
task.centeredOctahedralNo(10)
if __name__ == "__main__": main()
Output
1 7 25 63 129 231 377 575 833 1159
# Ruby program for
# Centered octahedral number
class CenteredOctahedral
def centeredOctahedralNo(k)
n = 0
# Print all initial k centered octahedral number
while (n < k)
# Formula
# (2n+1) (2n² + 2n + 3)
# ——————————————————————
# 3
# Calculate nth octahedral number
result = (((2 * n) + 1) *
(2 * (n * n) + (2 * n) + 3)) / 3
# Display Calculated value
print(" ", result)
n += 1
end
end
end
def main()
task = CenteredOctahedral.new()
# Centered octahedral numbers are
# —————————————————————————————————————————————
# 1, 7, 25, 63, 129, 231, 377, 575, 833,
# 1159, 1561, 2047, 2625, 3303, 4089, 4991,
# 6017, 7175, 8473, 9919, 11521, 13287, 15225,
# 17343, 19649, 22151, 24857, 27775, 30913,
# 34279, 37881, 41727, 45825, 50183, 54809 ... etc
# Test k = 10
task.centeredOctahedralNo(10)
end
main()
Output
1 7 25 63 129 231 377 575 833 1159
// Scala program for
// Centered octahedral number
class CenteredOctahedral()
{
def centeredOctahedralNo(k: Int): Unit = {
var n: Int = 0;
// Print all initial k centered octahedral number
while (n < k)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
var result: Int = (((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3;
// Display Calculated value
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: CenteredOctahedral = new CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
}
Output
1 7 25 63 129 231 377 575 833 1159
// Swift 4 program for
// Centered octahedral number
class CenteredOctahedral
{
func centeredOctahedralNo(_ k: Int)
{
var n: Int = 0;
// Print all initial k centered octahedral number
while (n < k)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
let result: Int = (((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3;
// Display Calculated value
print(" ", result, terminator: "");
n += 1;
}
}
}
func main()
{
let task: CenteredOctahedral = CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
main();
Output
1 7 25 63 129 231 377 575 833 1159
// Kotlin program for
// Centered octahedral number
class CenteredOctahedral
{
fun centeredOctahedralNo(k: Int): Unit
{
var n: Int = 0;
// Print all initial k centered octahedral number
while (n < k)
{
// Formula
// (2n+1) (2n² + 2n + 3)
// ——————————————————————
// 3
// Calculate nth octahedral number
val result: Int = (((2 * n) + 1) *
(2 * (n * n) +
(2 * n) + 3)) / 3;
// Display Calculated value
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
val task: CenteredOctahedral = CenteredOctahedral();
// Centered octahedral numbers are
// —————————————————————————————————————————————
// 1, 7, 25, 63, 129, 231, 377, 575, 833,
// 1159, 1561, 2047, 2625, 3303, 4089, 4991,
// 6017, 7175, 8473, 9919, 11521, 13287, 15225,
// 17343, 19649, 22151, 24857, 27775, 30913,
// 34279, 37881, 41727, 45825, 50183, 54809 ... etc
// Test k = 10
task.centeredOctahedralNo(10);
}
Output
1 7 25 63 129 231 377 575 833 1159
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