Centered tetrahedral number

Here given code implementation process.

// C Program for
// Centered tetrahedral number
#include <stdio.h>

void centeredTetrahedral(int k )
{
    // Print all initial k centered tetrahedral number
    for (int n = 0; n < k; ++n)
    {
        // Formula
        //   n*(n+1)*(n+2)
        // ————————————— 
        //       6

        // Calculate nth tetrahedral number
        int result  =  (n*(n+1)*(n+2)) / 6 ;

        // Display Calculated value
        printf("  %d",result);
    }
}

int main() {

    // Centered tetrahedral number are
    // —————————————————————————————————————————————
    //  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
    //  364, 455, 560, 680, 816, 969, 1140, 1330, 
    //  1540, 1771, 2024, 2300, 2600 ... etc
  
    // Test k = 10
    centeredTetrahedral(10);
    return 0;
}

Output

  0  1  4  10  20  35  56  84  120  165
// Java program for
// Centered tetrahedral number
public class CenteredTetrahedral
{
	public void centeredTetrahedralNo(int k)
	{
		// Print all initial k centered tetrahedral number
		for (int n = 0; n < k; ++n)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			int result = (n * (n + 1) * (n + 2)) / 6;
			// Display Calculated value
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		CenteredTetrahedral task = new CenteredTetrahedral();
		// Centered tetrahedral number are
		// —————————————————————————————————————————————
		//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
		//  364, 455, 560, 680, 816, 969, 1140, 1330, 
		//  1540, 1771, 2024, 2300, 2600 ... etc
		// Test k = 10
		task.centeredTetrahedralNo(10);
	}
}

Output

 0 1 4 10 20 35 56 84 120 165
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered tetrahedral number
class CenteredTetrahedral
{
	public: void centeredTetrahedralNo(int k)
	{
		// Print all initial k centered tetrahedral number
		for (int n = 0; n < k; ++n)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			int result = (n *(n + 1) *(n + 2)) / 6;
			// Display Calculated value
			cout << " " << result;
		}
	}
};
int main()
{
	CenteredTetrahedral *task = new CenteredTetrahedral();
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
	// Test k = 10
	task->centeredTetrahedralNo(10);
	return 0;
}

Output

 0 1 4 10 20 35 56 84 120 165
// Include namespace system
using System;
// Csharp program for
// Centered tetrahedral number
public class CenteredTetrahedral
{
	public void centeredTetrahedralNo(int k)
	{
		// Print all initial k centered tetrahedral number
		for (int n = 0; n < k; ++n)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			int result = (n * (n + 1) * (n + 2)) / 6;
			// Display Calculated value
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		CenteredTetrahedral task = new CenteredTetrahedral();
		// Centered tetrahedral number are
		// —————————————————————————————————————————————
		//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
		//  364, 455, 560, 680, 816, 969, 1140, 1330, 
		//  1540, 1771, 2024, 2300, 2600 ... etc
		// Test k = 10
		task.centeredTetrahedralNo(10);
	}
}

Output

 0 1 4 10 20 35 56 84 120 165
package main
import "fmt"
// Go program for
// Centered tetrahedral number

func centeredTetrahedralNo(k int) {
	// Print all initial k centered tetrahedral number
	for n := 0 ; n < k ; n++ {
		// Formula
		//   n*(n+1)*(n+2)
		// ————————————— 
		//       6
		// Calculate nth tetrahedral number
		var result int = (n * (n + 1) * (n + 2)) / 6
		// Display Calculated value
		fmt.Print(" ", result)
	}
}
func main() {
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
	// Test k = 10
	centeredTetrahedralNo(10)
}

Output

 0 1 4 10 20 35 56 84 120 165
<?php
// Php program for
// Centered tetrahedral number
class CenteredTetrahedral
{
	public	function centeredTetrahedralNo($k)
	{
		// Print all initial k centered tetrahedral number
		for ($n = 0; $n < $k; ++$n)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			$result = (int)(($n * ($n + 1) * ($n + 2)) / 6);
			// Display Calculated value
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new CenteredTetrahedral();
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
	// Test k = 10
	$task->centeredTetrahedralNo(10);
}
main();

Output

 0 1 4 10 20 35 56 84 120 165
// Node JS program for
// Centered tetrahedral number
class CenteredTetrahedral
{
	centeredTetrahedralNo(k)
	{
		// Print all initial k centered tetrahedral number
		for (var n = 0; n < k; ++n)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			var result = parseInt((n * (n + 1) * (n + 2)) / 6);
			// Display Calculated value
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new CenteredTetrahedral();
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
	// Test k = 10
	task.centeredTetrahedralNo(10);
}
main();

Output

 0 1 4 10 20 35 56 84 120 165
#  Python 3 program for
#  Centered tetrahedral number
class CenteredTetrahedral :
	def centeredTetrahedralNo(self, k) :
		n = 0
		#  Print all initial k centered tetrahedral number
		while (n < k) :
			#  Formula
			#    n*(n+1)*(n+2)
			#  ————————————— 
			#        6
			#  Calculate nth tetrahedral number
			result = int((n * (n + 1) * (n + 2)) / 6)
			#  Display Calculated value
			print(" ", result, end = "")
			n += 1
		

def main() :
	task = CenteredTetrahedral()
	#  Centered tetrahedral number are
	#  —————————————————————————————————————————————
	#   0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	#   364, 455, 560, 680, 816, 969, 1140, 1330, 
	#   1540, 1771, 2024, 2300, 2600 ... etc
	#  Test k = 10
	task.centeredTetrahedralNo(10)

if __name__ == "__main__": main()

Output

  0  1  4  10  20  35  56  84  120  165
#  Ruby program for
#  Centered tetrahedral number
class CenteredTetrahedral 
	def centeredTetrahedralNo(k) 
		n = 0
		#  Print all initial k centered tetrahedral number
		while (n < k) 
			#  Formula
			#    n*(n+1)*(n+2)
			#  ————————————— 
			#        6
			#  Calculate nth tetrahedral number
			result = (n * (n + 1) * (n + 2)) / 6
			#  Display Calculated value
			print(" ", result)
			n += 1
		end
	end
end

def main() 
	task = CenteredTetrahedral.new()
	#  Centered tetrahedral number are
	#  —————————————————————————————————————————————
	#   0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	#   364, 455, 560, 680, 816, 969, 1140, 1330, 
	#   1540, 1771, 2024, 2300, 2600 ... etc
	#  Test k = 10
	task.centeredTetrahedralNo(10)
end

main()

Output

 0 1 4 10 20 35 56 84 120 165
// Scala program for
// Centered tetrahedral number
class CenteredTetrahedral()
{
	def centeredTetrahedralNo(k: Int): Unit = {
		var n: Int = 0;
		// Print all initial k centered tetrahedral number
		while (n < k)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			var result: Int = (n * (n + 1) * (n + 2)) / 6;
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: CenteredTetrahedral = new CenteredTetrahedral();
		// Centered tetrahedral number are
		// —————————————————————————————————————————————
		//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
		//  364, 455, 560, 680, 816, 969, 1140, 1330, 
		//  1540, 1771, 2024, 2300, 2600 ... etc
  
		// Test k = 10
		task.centeredTetrahedralNo(10);
	}
}

Output

 0 1 4 10 20 35 56 84 120 165
// Swift 4 program for
// Centered tetrahedral number
class CenteredTetrahedral
{
	func centeredTetrahedralNo(_ k: Int)
	{
		var n: Int = 0;
		// Print all initial k centered tetrahedral number
		while (n < k)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			let result: Int = (n * (n + 1) * (n + 2)) / 6;
			// Display Calculated value
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: CenteredTetrahedral = CenteredTetrahedral();
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
  
	// Test k = 10
	task.centeredTetrahedralNo(10);
}
main();

Output

  0  1  4  10  20  35  56  84  120  165
// Kotlin program for
// Centered tetrahedral number
class CenteredTetrahedral
{
	fun centeredTetrahedralNo(k: Int): Unit
	{
		var n: Int = 0;
		// Print all initial k centered tetrahedral number
		while (n < k)
		{
			// Formula
			//   n*(n+1)*(n+2)
			// ————————————— 
			//       6
			// Calculate nth tetrahedral number
			val result: Int = (n * (n + 1) * (n + 2)) / 6;
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: CenteredTetrahedral = CenteredTetrahedral();
	// Centered tetrahedral number are
	// —————————————————————————————————————————————
	//  0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 
	//  364, 455, 560, 680, 816, 969, 1140, 1330, 
	//  1540, 1771, 2024, 2300, 2600 ... etc
	// Test k = 10
	task.centeredTetrahedralNo(10);
}

Output

 0 1 4 10 20 35 56 84 120 165


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







© 2021, kalkicode.com, All rights reserved