Centered Nonagonal Number

Here given code implementation process.

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

void centeredNonagonalNo(int k)
{
	// Print all initial k centered nonagonal number
	for (int n = 1; n <= k; ++n)
	{
		// Centered nonagonal formula
		//  (3n-2) (3n-1)
		//  —————————————
		//       2
		// Centered nonagonal number
		int result = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
	// Test 
	// k  = 10
	centeredNonagonalNo(10);
	return 0;
}

Output

  1  10  28  55  91  136  190  253  325  406
// Java program for
// Centered Nonagonal Number
public class NonagonalNumber
{
	public void centeredNonagonalNo(int k)
	{
		// Print all initial k centered nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
			// Centered nonagonal number
			int result = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		NonagonalNumber task = new NonagonalNumber();
		// Centered Nonagonal numbers
		// --------------------------------------
		// 1, 10, 28, 55, 91, 136, 190, 253, 
		// 325, 406, 496, 595, 703, 820, 946 ... etc.
		// Test 
		// k  = 10
		task.centeredNonagonalNo(10);
	}
}

Output

 1 10 28 55 91 136 190 253 325 406
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered Nonagonal Number
class NonagonalNumber
{
	public: void centeredNonagonalNo(int k)
	{
		// Print all initial k centered nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			int result = (((3 *n) - 2) *((3 *n) - 1)) / 2;
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	NonagonalNumber *task = new NonagonalNumber();
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
  
	// Test 
	// k  = 10
	task->centeredNonagonalNo(10);
	return 0;
}

Output

 1 10 28 55 91 136 190 253 325 406
// Include namespace system
using System;
// Csharp program for
// Centered Nonagonal Number
public class NonagonalNumber
{
	public void centeredNonagonalNo(int k)
	{
		// Print all initial k centered nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			int result = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		NonagonalNumber task = new NonagonalNumber();
		// Centered Nonagonal numbers
		// --------------------------------------
		// 1, 10, 28, 55, 91, 136, 190, 253, 
		// 325, 406, 496, 595, 703, 820, 946 ... etc.
      
		// Test 
		// k  = 10
		task.centeredNonagonalNo(10);
	}
}

Output

 1 10 28 55 91 136 190 253 325 406
package main
import "fmt"
// Go program for
// Centered Nonagonal Number

func centeredNonagonalNo(k int) {
	// Print all initial k centered nonagonal number
	for n := 1 ; n <= k ; n++ {
		// Centered nonagonal formula
		//  (3n-2) (3n-1)
		//  —————————————
		//       2

		// Centered nonagonal number
		var result int = (((3 * n) - 2) * ((3 * n) - 1)) / 2
		
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {

	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
	
	// Test 
	// k  = 10
	centeredNonagonalNo(10)
}

Output

 1 10 28 55 91 136 190 253 325 406
<?php
// Php program for
// Centered Nonagonal Number
class NonagonalNumber
{
	public	function centeredNonagonalNo($k)
	{
		// Print all initial k centered nonagonal number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			$result = (int)((((3 * $n) - 2) * ((3 * $n) - 1)) / 2);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new NonagonalNumber();
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
  
	// Test 
	// k  = 10
	$task->centeredNonagonalNo(10);
}
main();

Output

 1 10 28 55 91 136 190 253 325 406
// Node JS program for
// Centered Nonagonal Number
class NonagonalNumber
{
	centeredNonagonalNo(k)
	{
		// Print all initial k centered nonagonal number
		for (var n = 1; n <= k; ++n)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			var result = parseInt((((3 * n) - 2) * ((3 * n) - 1)) / 2);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new NonagonalNumber();
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
	// Test 
	// k  = 10
	task.centeredNonagonalNo(10);
}
main();

Output

 1 10 28 55 91 136 190 253 325 406
#  Python 3 program for
#  Centered Nonagonal Number
class NonagonalNumber :
	def centeredNonagonalNo(self, k) :
		n = 1
		#  Print all initial k centered nonagonal number
		while (n <= k) :
			#  Centered nonagonal formula
			#   (3n-2) (3n-1)
			#   —————————————
			#        2
            
			#  Centered nonagonal number
			result = int((((3 * n) - 2) * ((3 * n) - 1)) / 2)

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

def main() :
	task = NonagonalNumber()
	#  Centered Nonagonal numbers
	#  --------------------------------------
	#  1, 10, 28, 55, 91, 136, 190, 253, 
	#  325, 406, 496, 595, 703, 820, 946 ... etc.
    
	#  Test 
	#  k  = 10
	task.centeredNonagonalNo(10)

if __name__ == "__main__": main()

Output

  1  10  28  55  91  136  190  253  325  406
#  Ruby program for
#  Centered Nonagonal Number
class NonagonalNumber 
	def centeredNonagonalNo(k) 
		n = 1
		#  Print all initial k centered nonagonal number
		while (n <= k) 
			#  Centered nonagonal formula
			#   (3n-2) (3n-1)
			#   —————————————
			#        2
            
			#  Centered nonagonal number
			result = (((3 * n) - 2) * ((3 * n) - 1)) / 2

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

	end

end

def main() 
	task = NonagonalNumber.new()
	#  Centered Nonagonal numbers
	#  --------------------------------------
	#  1, 10, 28, 55, 91, 136, 190, 253, 
	#  325, 406, 496, 595, 703, 820, 946 ... etc.
    
	#  Test 
	#  k  = 10
	task.centeredNonagonalNo(10)
end

main()

Output

 1 10 28 55 91 136 190 253 325 406
// Scala program for
// Centered Nonagonal Number
class NonagonalNumber()
{
	def centeredNonagonalNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k centered nonagonal number
		while (n <= k)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			var result: Int = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: NonagonalNumber = new NonagonalNumber();
		// Centered Nonagonal numbers
		// --------------------------------------
		// 1, 10, 28, 55, 91, 136, 190, 253, 
		// 325, 406, 496, 595, 703, 820, 946 ... etc.
		// Test 
		// k  = 10
		task.centeredNonagonalNo(10);
	}
}

Output

 1 10 28 55 91 136 190 253 325 406
// Swift 4 program for
// Centered Nonagonal Number
class NonagonalNumber
{
	func centeredNonagonalNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k centered nonagonal number
		while (n <= k)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
			// Centered nonagonal number
			let result: Int = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: NonagonalNumber = NonagonalNumber();
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
	// Test 
	// k  = 10
	task.centeredNonagonalNo(10);
}
main();

Output

  1  10  28  55  91  136  190  253  325  406
// Kotlin program for
// Centered Nonagonal Number
class NonagonalNumber
{
	fun centeredNonagonalNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k centered nonagonal number
		while (n <= k)
		{
			// Centered nonagonal formula
			//  (3n-2) (3n-1)
			//  —————————————
			//       2
          
			// Centered nonagonal number
			val result: Int = (((3 * n) - 2) * ((3 * n) - 1)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: NonagonalNumber = NonagonalNumber();
	// Centered Nonagonal numbers
	// --------------------------------------
	// 1, 10, 28, 55, 91, 136, 190, 253, 
	// 325, 406, 496, 595, 703, 820, 946 ... etc.
  
	// Test 
	// k  = 10
	task.centeredNonagonalNo(10);
}

Output

 1 10 28 55 91 136 190 253 325 406


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