Skip to main content

Pentagonal pyramidal number

Here given code implementation process.

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

void pentagonalPyramidalNo(int k)
{
	// Print all initial k pentagonal pyramidal number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		//  n²(n+1)
		//  —————————
		//     2
      
		// Calculate nth pentagonal pyramidal number
		int result = ((n *n) *(n + 1)) / 2;
      
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	pentagonalPyramidalNo(10);
	return 0;
}

Output

  1  6  18  40  75  126  196  288  405  550
// Java program for
// Pentagonal pyramidal number
public class PentagonalNumber
{
	public void pentagonalPyramidalNo(int k)
	{
		// Print all initial k pentagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
			// Calculate nth pentagonal pyramidal number
			int result = ((n * n) * (n + 1)) / 2;
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		PentagonalNumber task = new PentagonalNumber();
		//  Pentagonal pyramidal number are
		// —————————————————————————————————————————————
		// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
		// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
		// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
		// 11368, 12615, 13950, 15376, 16896, 18513, 
		// 20230, 22050, 23976 etc.
		// k = 10
		task.pentagonalPyramidalNo(10);
	}
}

Output

 1 6 18 40 75 126 196 288 405 550
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Pentagonal pyramidal number

class PentagonalNumber
{
	public: void pentagonalPyramidalNo(int k)
	{
		// Print all initial k pentagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			int result = ((n *n) *(n + 1)) / 2;
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	PentagonalNumber *task = new PentagonalNumber();
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	task->pentagonalPyramidalNo(10);
	return 0;
}

Output

 1 6 18 40 75 126 196 288 405 550
// Include namespace system
using System;
// Csharp program for
// Pentagonal pyramidal number
public class PentagonalNumber
{
	public void pentagonalPyramidalNo(int k)
	{
		// Print all initial k pentagonal pyramidal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			int result = ((n * n) * (n + 1)) / 2;
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		PentagonalNumber task = new PentagonalNumber();
		//  Pentagonal pyramidal number are
		// —————————————————————————————————————————————
		// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
		// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
		// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
		// 11368, 12615, 13950, 15376, 16896, 18513, 
		// 20230, 22050, 23976 etc.
      
		// k = 10
		task.pentagonalPyramidalNo(10);
	}
}

Output

 1 6 18 40 75 126 196 288 405 550
package main
import "fmt"
// Go program for
// Pentagonal pyramidal number

func pentagonalPyramidalNo(k int) {
	// Print all initial k pentagonal pyramidal number
	for n := 1 ; n <= k ; n++ {
		// Formula
		//  n²(n+1)
		//  —————————
		//     2
      
		// Calculate nth pentagonal pyramidal number
		var result int = ((n * n) * (n + 1)) / 2
      
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {
	
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	pentagonalPyramidalNo(10)
}

Output

 1 6 18 40 75 126 196 288 405 550
<?php
// Php program for
// Pentagonal pyramidal number
class PentagonalNumber
{
	public	function pentagonalPyramidalNo($k)
	{
		// Print all initial k pentagonal pyramidal number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			$result = (int)((($n * $n) * ($n + 1)) / 2);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new PentagonalNumber();
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	$task->pentagonalPyramidalNo(10);
}
main();

Output

 1 6 18 40 75 126 196 288 405 550
// Node JS program for
// Pentagonal pyramidal number
class PentagonalNumber
{
	pentagonalPyramidalNo(k)
	{
		// Print all initial k pentagonal pyramidal number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			//  n²(n+1)
			//  ———————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			var result = parseInt(((n * n) * (n + 1)) / 2);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new PentagonalNumber();
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	task.pentagonalPyramidalNo(10);
}
main();

Output

 1 6 18 40 75 126 196 288 405 550
#  Python 3 program for
#  Pentagonal pyramidal number
class PentagonalNumber :
	def pentagonalPyramidalNo(self, k) :
		n = 1
		#  Print all initial k pentagonal pyramidal number
		while (n <= k) :
			#  Formula
			#   n²(n+1)
			#   —————————
			#      2
            
			#  Calculate nth pentagonal pyramidal number
			result = int(((n * n) * (n + 1)) / 2)

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

def main() :
	task = PentagonalNumber()
	#   Pentagonal pyramidal number are
	#  —————————————————————————————————————————————
	#  1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	#  936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	#  4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	#  11368, 12615, 13950, 15376, 16896, 18513, 
	#  20230, 22050, 23976 etc.
    
	#  k = 10
	task.pentagonalPyramidalNo(10)

if __name__ == "__main__": main()

Output

  1  6  18  40  75  126  196  288  405  550
#  Ruby program for
#  Pentagonal pyramidal number
class PentagonalNumber 
	def pentagonalPyramidalNo(k) 
		n = 1
		#  Print all initial k pentagonal pyramidal number
		while (n <= k) 
			#  Formula
			#   n²(n+1)
			#   —————————
			#      2
            
			#  Calculate nth pentagonal pyramidal number
			result = ((n * n) * (n + 1)) / 2

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

	end

end

def main() 
	task = PentagonalNumber.new()
	#   Pentagonal pyramidal number are
	#  —————————————————————————————————————————————
	#  1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	#  936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	#  4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	#  11368, 12615, 13950, 15376, 16896, 18513, 
	#  20230, 22050, 23976 etc.
    
	#  k = 10
	task.pentagonalPyramidalNo(10)
end

main()

Output

 1 6 18 40 75 126 196 288 405 550
// Scala program for
// Pentagonal pyramidal number
class PentagonalNumber()
{
	def pentagonalPyramidalNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k pentagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			var result: Int = ((n * n) * (n + 1)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: PentagonalNumber = new PentagonalNumber();
		//  Pentagonal pyramidal number are
		// —————————————————————————————————————————————
		// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
		// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
		// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
		// 11368, 12615, 13950, 15376, 16896, 18513, 
		// 20230, 22050, 23976 etc.
  
		// k = 10
		task.pentagonalPyramidalNo(10);
	}
}

Output

 1 6 18 40 75 126 196 288 405 550
// Swift 4 program for
// Pentagonal pyramidal number
class PentagonalNumber
{
	func pentagonalPyramidalNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k pentagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n²(n+1)
			//  —————————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			let result: Int = ((n * n) * (n + 1)) / 2;
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: PentagonalNumber = PentagonalNumber();
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	task.pentagonalPyramidalNo(10);
}
main();

Output

  1  6  18  40  75  126  196  288  405  550
// Kotlin program for
// Pentagonal pyramidal number
class PentagonalNumber
{
	fun pentagonalPyramidalNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k pentagonal pyramidal number
		while (n <= k)
		{
			// Formula
			//  n²(n+1)
			//  ———————
			//     2
          
			// Calculate nth pentagonal pyramidal number
			val result: Int = ((n * n) * (n + 1)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: PentagonalNumber = PentagonalNumber();
	//  Pentagonal pyramidal number are
	// —————————————————————————————————————————————
	// 1, 6, 18, 40, 75, 126, 196, 288, 405, 550, 726, 
	// 936, 1183, 1470, 1800, 2176, 2601, 3078, 3610, 
	// 4200, 4851, 5566, 6348, 7200, 8125, 9126, 10206, 
	// 11368, 12615, 13950, 15376, 16896, 18513, 
	// 20230, 22050, 23976 etc.
  
	// k = 10
	task.pentagonalPyramidalNo(10);
}

Output

 1 6 18 40 75 126 196 288 405 550




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.

New Comment