Nonagonal number

Here given code implementation process.

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

void nonagonalNo(int k)
{
	// Print all initial k nonagonal number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		//  n(7n-5)
		// ————————
		//    2
      
		// Calculate nth nonagonal number
		int result = (n *(7 *n - 5)) / 2;
      
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	nonagonalNo(10);
	return 0;
}

Output

  1  9  24  46  75  111  154  204  261  325
// Java program for
// Nonagonal number
public class NonagonalNumber
{
	public void nonagonalNo(int k)
	{
		// Print all initial k nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			int result = (n * (7 * n - 5)) / 2;
          
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		NonagonalNumber task = new NonagonalNumber();
		//  Nonagonal number are
		// —————————————————————————————————————————————
		//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
		// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
		// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
		// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
		// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
      
		// k = 10
		task.nonagonalNo(10);
	}
}

Output

 1 9 24 46 75 111 154 204 261 325
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Nonagonal number

class NonagonalNumber
{
	public: void nonagonalNo(int k)
	{
		// Print all initial k nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//     2
          
			// Calculate nth nonagonal number
			int result = (n *(7 *n - 5)) / 2;
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	NonagonalNumber *task = new NonagonalNumber();
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	task->nonagonalNo(10);
	return 0;
}

Output

 1 9 24 46 75 111 154 204 261 325
package main
import "fmt"
// Go program for
// Nonagonal number

func nonagonalNo(k int) {
	// Print all initial k nonagonal number
	for n := 1 ; n <= k ; n++ {
		// Formula
		//  n(7n-5)
		// ————————
		//    2

		// Calculate nth nonagonal number
		var result int = (n * (7 * n - 5)) / 2
		
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {
	
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc

	// k = 10
	nonagonalNo(10)
}

Output

 1 9 24 46 75 111 154 204 261 325
// Include namespace system
using System;
// Csharp program for
// Nonagonal number
public class NonagonalNumber
{
	public void nonagonalNo(int k)
	{
		// Print all initial k nonagonal number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			int result = (n * (7 * n - 5)) / 2;
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		NonagonalNumber task = new NonagonalNumber();
		//  Nonagonal number are
		// —————————————————————————————————————————————
		//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
		// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
		// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
		// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
		// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
      
		// k = 10
		task.nonagonalNo(10);
	}
}

Output

 1 9 24 46 75 111 154 204 261 325
<?php
// Php program for
// Nonagonal number
class NonagonalNumber
{
	public	function nonagonalNo($k)
	{
		// Print all initial k nonagonal number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			$result = (int)(($n * (7 * $n - 5)) / 2);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new NonagonalNumber();
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	$task->nonagonalNo(10);
}
main();

Output

 1 9 24 46 75 111 154 204 261 325
// Node JS program for
// Nonagonal number
class NonagonalNumber
{
	nonagonalNo(k)
	{
		// Print all initial k nonagonal number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			var result = parseInt((n * (7 * n - 5)) / 2);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new NonagonalNumber();
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	task.nonagonalNo(10);
}
main();

Output

 1 9 24 46 75 111 154 204 261 325
#  Python 3 program for
#  Nonagonal number
class NonagonalNumber :
	def nonagonalNo(self, k) :
		n = 1
		#  Print all initial k nonagonal number
		while (n <= k) :
			#  Formula
			#   n(7n-5)
			#  ————————
			#     2
            
			#  Calculate nth nonagonal number
			result = int((n * (7 * n - 5)) / 2)

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

def main() :
	task = NonagonalNumber()
	#   Nonagonal number are
	#  —————————————————————————————————————————————
	#   1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	#  474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	#  1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	#  2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	#  4699, 4959, 5226, 5500, 5781, 6069 ... etc
    
	#  k = 10
	task.nonagonalNo(10)

if __name__ == "__main__": main()

Output

  1  9  24  46  75  111  154  204  261  325
#  Ruby program for
#  Nonagonal number
class NonagonalNumber 
	def nonagonalNo(k) 
		n = 1
		#  Print all initial k nonagonal number
		while (n <= k) 
			#  Formula
			#   n(7n-5)
			#  ————————
			#     2
            
			#  Calculate nth nonagonal number
			result = (n * (7 * n - 5)) / 2

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

	end

end

def main() 
	task = NonagonalNumber.new()
	#   Nonagonal number are
	#  —————————————————————————————————————————————
	#   1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	#  474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	#  1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	#  2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	#  4699, 4959, 5226, 5500, 5781, 6069 ... etc
    
	#  k = 10
	task.nonagonalNo(10)
end

main()

Output

 1 9 24 46 75 111 154 204 261 325
// Scala program for
// Nonagonal number
class NonagonalNumber()
{
	def nonagonalNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k nonagonal number
		while (n <= k)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			var result: Int = (n * (7 * n - 5)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: NonagonalNumber = new NonagonalNumber();
		//  Nonagonal number are
		// —————————————————————————————————————————————
		//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
		// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
		// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
		// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
		// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
		// k = 10
		task.nonagonalNo(10);
	}
}

Output

 1 9 24 46 75 111 154 204 261 325
// Swift 4 program for
// Nonagonal number
class NonagonalNumber
{
	func nonagonalNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k nonagonal number
		while (n <= k)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			let result: Int = (n * (7 * n - 5)) / 2;
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: NonagonalNumber = NonagonalNumber();
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	task.nonagonalNo(10);
}
main();

Output

  1  9  24  46  75  111  154  204  261  325
// Kotlin program for
// Nonagonal number
class NonagonalNumber
{
	fun nonagonalNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k nonagonal number
		while (n <= k)
		{
			// Formula
			//  n(7n-5)
			// ————————
			//    2
          
			// Calculate nth nonagonal number
			val result: Int = (n * (7 * n - 5)) / 2;
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: NonagonalNumber = NonagonalNumber();
	//  Nonagonal number are
	// —————————————————————————————————————————————
	//  1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 
	// 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 
	// 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 
	// 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 
	// 4699, 4959, 5226, 5500, 5781, 6069 ... etc
  
	// k = 10
	task.nonagonalNo(10);
}

Output

 1 9 24 46 75 111 154 204 261 325


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