Hexagonal pyramidal number

Here given code implementation process.

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

void hexagonalPyramidalNo(int k)
{
	// Print all initial k hexagonal pyramidal number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		//  n(n+1)(4n-1)
		// ——————————————
		//       6
      
		// Calculate nth hexagonal pyramidal number
		int result = (n * (n + 1) * ((4 * n) - 1)) / 6;
      
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 37297 ... etc
	
    // k = 10
	hexagonalPyramidalNo(10);
	return 0;
}

Output

  1  7  22  50  95  161  252  372  525  715
// Java program for
// Heptagonal pyramidal number
public class HexagonalNumber
{
	public void hexagonalPyramidalNo(int k)
	{
		// Print all initial k hexagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			int result = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		HexagonalNumber task = new HexagonalNumber();
		//  Hexagonal pyramidal number are
		// —————————————————————————————————————————————
		//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
		//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
		//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
		//  12051, 13482, 15022, 16675, 18445, 20336, 
		//  22352, 24497, 26775, 29190, 31746, 34447, 
        //  37297 ... etc
      
		// k = 10
		task.hexagonalPyramidalNo(10);
	}
}

Output

 1 7 22 50 95 161 252 372 525 715
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Heptagonal pyramidal number
class HexagonalNumber
{
	public: void hexagonalPyramidalNo(int k)
	{
		// Print all initial k hexagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			int result = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	HexagonalNumber *task = new HexagonalNumber();
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
  
	// k = 10
	task->hexagonalPyramidalNo(10);
	return 0;
}

Output

 1 7 22 50 95 161 252 372 525 715
// Include namespace system
using System;
// Csharp program for
// Heptagonal pyramidal number
public class HexagonalNumber
{
	public void hexagonalPyramidalNo(int k)
	{
		// Print all initial k hexagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			int result = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		HexagonalNumber task = new HexagonalNumber();
		//  Hexagonal pyramidal number are
		// —————————————————————————————————————————————
		//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
		//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
		//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
		//  12051, 13482, 15022, 16675, 18445, 20336, 
		//  22352, 24497, 26775, 29190, 31746, 34447, 
		//  37297 ... etc
      
		// k = 10
		task.hexagonalPyramidalNo(10);
	}
}

Output

 1 7 22 50 95 161 252 372 525 715
package main
import "fmt"
// Go program for
// Heptagonal pyramidal number

func hexagonalPyramidalNo(k int) {
	// Print all initial k hexagonal pyramidal number
	for n := 1 ; n <= k ; n++ {
		// Formula
		//  n(n+1)(4n-1)
		// ——————————————
		//       6
      
		// Calculate nth hexagonal pyramidal number
		var result int = (n * (n + 1) * ((4 * n) - 1)) / 6
      
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {

	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
  
	// k = 10
	hexagonalPyramidalNo(10)
}

Output

 1 7 22 50 95 161 252 372 525 715
<?php
// Php program for
// Heptagonal pyramidal number
class HexagonalNumber
{
	public	function hexagonalPyramidalNo($k)
	{
		// Print all initial k hexagonal pyramidal number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			$result = (int)(($n * ($n + 1) * ((4 * $n) - 1)) / 6);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new HexagonalNumber();
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
  
	// k = 10
	$task->hexagonalPyramidalNo(10);
}
main();

Output

 1 7 22 50 95 161 252 372 525 715
// Node JS program for
// Heptagonal pyramidal number
class HexagonalNumber
{
	hexagonalPyramidalNo(k)
	{
		// Print all initial k hexagonal pyramidal number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			var result = parseInt((n * (n + 1) * ((4 * n) - 1)) / 6);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new HexagonalNumber();
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
  
	// k = 10
	task.hexagonalPyramidalNo(10);
}
main();

Output

 1 7 22 50 95 161 252 372 525 715
#  Python 3 program for
#  Heptagonal pyramidal number
class HexagonalNumber :
	def hexagonalPyramidalNo(self, k) :
		n = 1
		#  Print all initial k hexagonal pyramidal number
		while (n <= k) :
			#  Formula
			#   n(n+1)(4n-1)
			#  ——————————————
			#        6
            
			#  Calculate nth hexagonal pyramidal number
			result = int((n * (n + 1) * ((4 * n) - 1)) / 6)

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

def main() :
	task = HexagonalNumber()
	#   Hexagonal pyramidal number are
	#  —————————————————————————————————————————————
	#   1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	#   946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	#   4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	#   12051, 13482, 15022, 16675, 18445, 20336, 
	#   22352, 24497, 26775, 29190, 31746, 34447, 
	#   37297 ... etc
    
	#  k = 10
	task.hexagonalPyramidalNo(10)

if __name__ == "__main__": main()

Output

  1  7  22  50  95  161  252  372  525  715
#  Ruby program for
#  Heptagonal pyramidal number
class HexagonalNumber 
	def hexagonalPyramidalNo(k) 
		n = 1
		#  Print all initial k hexagonal pyramidal number
		while (n <= k) 
			#  Formula
			#   n(n+1)(4n-1)
			#  ——————————————
			#        6
            
			#  Calculate nth hexagonal pyramidal number
			result = (n * (n + 1) * ((4 * n) - 1)) / 6

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

	end

end

def main() 
	task = HexagonalNumber.new()
	#   Hexagonal pyramidal number are
	#  —————————————————————————————————————————————
	#   1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	#   946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	#   4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	#   12051, 13482, 15022, 16675, 18445, 20336, 
	#   22352, 24497, 26775, 29190, 31746, 34447, 
	#   37297 ... etc
    
	#  k = 10
	task.hexagonalPyramidalNo(10)
end

main()

Output

 1 7 22 50 95 161 252 372 525 715
// Scala program for
// Heptagonal pyramidal number
class HexagonalNumber()
{
	def hexagonalPyramidalNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k hexagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			var result: Int = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: HexagonalNumber = new HexagonalNumber();
		//  Hexagonal pyramidal number are
		// —————————————————————————————————————————————
		//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
		//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
		//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
		//  12051, 13482, 15022, 16675, 18445, 20336, 
		//  22352, 24497, 26775, 29190, 31746, 34447, 
		//  37297 ... etc
  
		// k = 10
		task.hexagonalPyramidalNo(10);
	}
}

Output

 1 7 22 50 95 161 252 372 525 715
// Swift 4 program for
// Heptagonal pyramidal number
class HexagonalNumber
{
	func hexagonalPyramidalNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k hexagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			let result: Int = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: HexagonalNumber = HexagonalNumber();
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
  
	// k = 10
	task.hexagonalPyramidalNo(10);
}
main();

Output

  1  7  22  50  95  161  252  372  525  715
// Kotlin program for
// Heptagonal pyramidal number
class HexagonalNumber
{
	fun hexagonalPyramidalNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k hexagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n(n+1)(4n-1)
			// ——————————————
			//       6
          
			// Calculate nth hexagonal pyramidal number
			val result: Int = (n * (n + 1) * ((4 * n) - 1)) / 6;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: HexagonalNumber = HexagonalNumber();
	//  Hexagonal pyramidal number are
	// —————————————————————————————————————————————
	//  1, 7, 22, 50, 95, 161, 252, 372, 525, 715, 
	//  946, 1222, 1547, 1925, 2360, 2856, 3417, 4047, 
	//  4750, 5530, 6391, 7337, 8372, 9500, 10725, 
	//  12051, 13482, 15022, 16675, 18445, 20336, 
	//  22352, 24497, 26775, 29190, 31746, 34447, 
	//  37297 ... etc
	// k = 10
	task.hexagonalPyramidalNo(10);
}

Output

 1 7 22 50 95 161 252 372 525 715


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