# Centered Cube Number

Here given code implementation process.

``````// C Program for
// Centered Cube Number
#include <stdio.h>

void centeredCubeNo(int k)
{
int ans = 0;
// Print all initial k centered cube number
for (int n = 0; n < k; ++n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)
// Calculate nth centered number
ans = ((2 *n) + 1) *((n *n) + n + 1);
// Display calculate number
printf("  %d", ans);
}
}
int main()
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc
// Test
// k = 10
centeredCubeNo(10);
return 0;
}``````

#### Output

``  1  9  35  91  189  341  559  855  1241  1729``
``````// Java program for
//  Centered Cube Number
public class CubeNumber
{
public void centeredCubeNo(int k)
{
int ans = 0;
// Print all initial k centered cube number
for (int n = 0; n < k; ++n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
System.out.print(" " + ans);
}
}
public static void main(String[] args)
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc
// Test
// k = 10
}
}``````

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
//  Centered Cube Number
class CubeNumber
{
public: void centeredCubeNo(int k)
{
int ans = 0;
// Print all initial k centered cube number
for (int n = 0; n < k; ++n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 *n) + 1) *((n *n) + n + 1);

// Display calculate number
cout << " " << ans;
}
}
};
int main()
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````// Include namespace system
using System;
// Csharp program for
//  Centered Cube Number
public class CubeNumber
{
public void centeredCubeNo(int k)
{
int ans = 0;
// Print all initial k centered cube number
for (int n = 0; n < k; ++n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
Console.Write(" " + ans);
}
}
public static void Main(String[] args)
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````package main
import "fmt"
// Go program for
// Centered Cube Number

func centeredCubeNo(k int) {
var ans int = 0
// Print all initial k centered cube number
for n := 0 ; n < k ; n++ {
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1)

// Display calculate number
fmt.Print(" ", ans)
}
}
func main() {
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````<?php
// Php program for
//  Centered Cube Number
class CubeNumber
{
public	function centeredCubeNo(\$k)
{
\$ans = 0;
// Print all initial k centered cube number
for (\$n = 0; \$n < \$k; ++\$n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
\$ans = ((2 * \$n) + 1) * ((\$n * \$n) + \$n + 1);

// Display calculate number
echo(" ".\$ans);
}
}
}

function main()
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````// Node JS program for
//  Centered Cube Number
class CubeNumber
{
centeredCubeNo(k)
{
var ans = 0;
// Print all initial k centered cube number
for (var n = 0; n < k; ++n)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
process.stdout.write(" " + ans);
}
}
}

function main()
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc
// Test
// k = 10
}
main();``````

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````#  Python 3 program for
#   Centered Cube Number
class CubeNumber :
def centeredCubeNo(self, k) :
ans = 0
n = 0
#  Print all initial k centered cube number
while (n < k) :
#  Centered cube
#  formula =  (2n + 1)(n²+n+1)

#  Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1)

#  Display calculate number
print(" ", ans, end = "")
n += 1

def main() :
#  Centered cube numbers
#  --------------------------------------
#  1, 9, 35, 91, 189, 341, 559, 855, 1241,
#  1729, 2331, 3059, 3925, 4941, 6119 .. etc

#  Test
#  k = 10

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

#### Output

``  1  9  35  91  189  341  559  855  1241  1729``
``````#  Ruby program for
#   Centered Cube Number
class CubeNumber
def centeredCubeNo(k)
ans = 0
n = 0
#  Print all initial k centered cube number
while (n < k)
#  Centered cube
#  formula =  (2n + 1)(n²+n+1)

#  Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1)

#  Display calculate number
print(" ", ans)
n += 1
end

end

end

def main()
#  Centered cube numbers
#  --------------------------------------
#  1, 9, 35, 91, 189, 341, 559, 855, 1241,
#  1729, 2331, 3059, 3925, 4941, 6119 .. etc

#  Test
#  k = 10
end

main()``````

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````// Scala program for
//  Centered Cube Number
class CubeNumber()
{
def centeredCubeNo(k: Int): Unit = {
var ans: Int = 0;
var n: Int = 0;
// Print all initial k centered cube number
while (n < k)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
print(" " + ans);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: CubeNumber = new CubeNumber();
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``
``````// Swift 4 program for
//  Centered Cube Number
class CubeNumber
{
func centeredCubeNo(_ k: Int)
{
var ans: Int = 0;
var n: Int = 0;
// Print all initial k centered cube number
while (n < k)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
print(" ", ans, terminator: "");
n += 1;
}
}
}
func main()
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

``  1  9  35  91  189  341  559  855  1241  1729``
``````// Kotlin program for
//  Centered Cube Number
class CubeNumber
{
fun centeredCubeNo(k: Int): Unit
{
var ans: Int ;
var n: Int = 0;
// Print all initial k centered cube number
while (n < k)
{
// Centered cube
// formula =  (2n + 1)(n²+n+1)

// Calculate nth centered number
ans = ((2 * n) + 1) * ((n * n) + n + 1);

// Display calculate number
print(" " + ans);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
// Centered cube numbers
// --------------------------------------
// 1, 9, 35, 91, 189, 341, 559, 855, 1241,
// 1729, 2331, 3059, 3925, 4941, 6119 .. etc

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

#### Output

`` 1 9 35 91 189 341 559 855 1241 1729``

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