Centered heptagonal number

Here given code implementation process.

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

void centeredHeptagonalNo(int k)
{
	// Print all initial k centered heptagonal number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		//   (7n² - 7n + 2) 
		//   ————————————————
		//         2
      
		// Calculate nth heptagonal number
		int result = (7 *(n *n) - 7 *n + 2) / 2;
		// Display Calculated value
		printf("  %d", result);
	}
}
int main()
{
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
	// n = 10
	centeredHeptagonalNo(10);
	return 0;
}

Output

  1  8  22  43  71  106  148  197  253  316
// Java program for
// Centered heptagonal number
public class CenteredHeptagonal
{
	public void centeredHeptagonalNo(int k)
	{
		// Print all initial k centered heptagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
          
			// Calculate nth heptagonal number
			int result = (7 * (n * n) - 7 * n + 2) / 2;
          
			// Display Calculated value
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		CenteredHeptagonal task = new CenteredHeptagonal();
		// Centered heptagonal number are
		// —————————————————————————————————————————————
		//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
		// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
		// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
		// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
		// 4922, 5188, 5461, 5741, 6028 ... etc
		// n = 10
		task.centeredHeptagonalNo(10);
	}
}

Output

 1 8 22 43 71 106 148 197 253 316
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered heptagonal number
class CenteredHeptagonal
{
	public: void centeredHeptagonalNo(int k)
	{
		// Print all initial k centered heptagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
          
			// Calculate nth heptagonal number
			int result = (7 *(n *n) - 7 *n + 2) / 2;
          
			// Display Calculated value
			cout << " " << result;
		}
	}
};
int main()
{
	CenteredHeptagonal *task = new CenteredHeptagonal();
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
	// n = 10
	task->centeredHeptagonalNo(10);
	return 0;
}

Output

 1 8 22 43 71 106 148 197 253 316
// Include namespace system
using System;
// Csharp program for
// Centered heptagonal number
public class CenteredHeptagonal
{
	public void centeredHeptagonalNo(int k)
	{
		// Print all initial k centered heptagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
			// Calculate nth heptagonal number
			int result = (7 * (n * n) - 7 * n + 2) / 2;
			// Display Calculated value
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		CenteredHeptagonal task = new CenteredHeptagonal();
		// Centered heptagonal number are
		// —————————————————————————————————————————————
		//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
		// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
		// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
		// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
		// 4922, 5188, 5461, 5741, 6028 ... etc
		// n = 10
		task.centeredHeptagonalNo(10);
	}
}

Output

 1 8 22 43 71 106 148 197 253 316
package main
import "fmt"
// Go program for
// Centered heptagonal number

func centeredHeptagonalNo(k int) {
	// Print all initial k centered heptagonal number
	for n := 1 ; n <= k ; n++ {
		// Formula
		//   (7n² - 7n + 2) 
		//   ————————————————
		//         2

		// Calculate nth heptagonal number
		var result int = (7 * (n * n) - 7 * n + 2) / 2
		
		// Display Calculated value
		fmt.Print(" ", result)
	}
}
func main() {

	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
	// test k = 10
	centeredHeptagonalNo(10)
}

Output

 1 8 22 43 71 106 148 197 253 316
<?php
// Php program for
// Centered heptagonal number
class CenteredHeptagonal
{
	public	function centeredHeptagonalNo($k)
	{
		// Print all initial k centered heptagonal number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
			// Calculate nth heptagonal number
			$result = (int)((7 * ($n * $n) - 7 * $n + 2) / 2);
			// Display Calculated value
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new CenteredHeptagonal();
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
	// n = 10
	$task->centeredHeptagonalNo(10);
}
main();

Output

 1 8 22 43 71 106 148 197 253 316
// Node JS program for
// Centered heptagonal number
class CenteredHeptagonal
{
	centeredHeptagonalNo(k)
	{
		// Print all initial k centered heptagonal number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
          
			// Calculate nth heptagonal number
			var result = parseInt((7 * (n * n) - 7 * n + 2) / 2);
			// Display Calculated value
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new CenteredHeptagonal();
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
	// n = 10
	task.centeredHeptagonalNo(10);
}
main();

Output

 1 8 22 43 71 106 148 197 253 316
#  Python 3 program for
#  Centered heptagonal number
class CenteredHeptagonal :
	def centeredHeptagonalNo(self, k) :
		n = 1
		#  Print all initial k centered heptagonal number
		while (n <= k) :
			#  Formula
			#    (7n² - 7n + 2) 
			#    ————————————————
			#          2
            
			#  Calculate nth heptagonal number
			result = int((7 * (n * n) - 7 * n + 2) / 2)

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

def main() :
	task = CenteredHeptagonal()
	#  Centered heptagonal number are
	#  —————————————————————————————————————————————
	#   1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	#  386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	#  1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	#  3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	#  4922, 5188, 5461, 5741, 6028 ... etc
    
	#  Test k = 10
	task.centeredHeptagonalNo(10)

if __name__ == "__main__": main()

Output

  1  8  22  43  71  106  148  197  253  316
#  Ruby program for
#  Centered heptagonal number
class CenteredHeptagonal 
	def centeredHeptagonalNo(k) 
		n = 1
		#  Print all initial k centered heptagonal number
		while (n <= k) 
			#  Formula
			#    (7n² - 7n + 2) 
			#    ————————————————
			#          2
            
			#  Calculate nth heptagonal number
			result = (7 * (n * n) - 7 * n + 2) / 2

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

	end

end

def main() 
	task = CenteredHeptagonal.new()
	#  Centered heptagonal number are
	#  —————————————————————————————————————————————
	#   1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	#  386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	#  1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	#  3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	#  4922, 5188, 5461, 5741, 6028 ... etc
	
    #  Test n = 10
	task.centeredHeptagonalNo(10)
end

main()

Output

 1 8 22 43 71 106 148 197 253 316
// Scala program for
// Centered heptagonal number
class CenteredHeptagonal()
{
	def centeredHeptagonalNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k centered heptagonal number
		while (n <= k)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
          
			// Calculate nth heptagonal number
			var result: Int = (7 * (n * n) - 7 * n + 2) / 2;
          
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: CenteredHeptagonal = new CenteredHeptagonal();
		// Centered heptagonal number are
		// —————————————————————————————————————————————
		//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
		// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
		// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
		// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
		// 4922, 5188, 5461, 5741, 6028 ... etc
		// test k = 10
		task.centeredHeptagonalNo(10);
	}
}

Output

 1 8 22 43 71 106 148 197 253 316
// Swift 4 program for
// Centered heptagonal number
class CenteredHeptagonal
{
	func centeredHeptagonalNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k centered heptagonal number
		while (n <= k)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
          
			// Calculate nth heptagonal number
			let result: Int = (7 * (n * n) - 7 * n + 2) / 2;
          
			// Display Calculated value
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: CenteredHeptagonal = CenteredHeptagonal();
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
  
	// test k = 10
	task.centeredHeptagonalNo(10);
}
main();

Output

  1  8  22  43  71  106  148  197  253  316
// Kotlin program for
// Centered heptagonal number
class CenteredHeptagonal
{
	fun centeredHeptagonalNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k centered heptagonal number
		while (n <= k)
		{
			// Formula
			//   (7n² - 7n + 2) 
			//   ————————————————
			//         2
			// Calculate nth heptagonal number
			val result: Int = (7 * (n * n) - 7 * n + 2) / 2;
			// Display Calculated value
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: CenteredHeptagonal = CenteredHeptagonal();
	// Centered heptagonal number are
	// —————————————————————————————————————————————
	//  1, 8, 22, 43, 71, 106, 148, 197, 253, 316, 
	// 386, 463, 547, 638, 736, 841, 953, 1072, 1198, 1331, 
	// 1471, 1618, 1772, 1933, 2101, 2276, 2458, 2647, 2843, 
	// 3046, 3256, 3473, 3697, 3928, 4166, 4411, 4663, 
	// 4922, 5188, 5461, 5741, 6028 ... etc
  
	// Test k = 10
	task.centeredHeptagonalNo(10);
}

Output

 1 8 22 43 71 106 148 197 253 316


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