Skip to main content

Centered Dodecagonal Number

In mathematics, the centered dodecagonal number is a polygonal number that represents the number of points in a centered dodecagon. It can be calculated using the formula 5n² + 5n + 1, where n is the index of the centered dodecagonal number. The centered dodecagonal numbers are a sequence of integers that have unique properties and can be useful in various mathematical applications.

Problem Statement

The problem is to write a program that generates and prints the first k centered dodecagonal numbers, where k is a user-defined input. The program should calculate each centered dodecagonal number using the formula mentioned above and display them in a formatted manner.

Example

Let's consider the case where we want to find the first 10 centered dodecagonal numbers. Using the provided formula, we can calculate the centered dodecagonal numbers as follows:

  • For n = 0: 5(0²) + 5(0) + 1 = 1
  • For n = 1: 5(1²) + 5(1) + 1 = 11
  • For n = 2: 5(2²) + 5(2) + 1 = 31
  • For n = 3: 5(3²) + 5(3) + 1 = 61
  • For n = 4: 5(4²) + 5(4) + 1 = 101
  • For n = 5: 5(5²) + 5(5) + 1 = 151
  • For n = 6: 5(6²) + 5(6) + 1 = 211
  • For n = 7: 5(7²) + 5(7) + 1 = 281
  • For n = 8: 5(8²) + 5(8) + 1 = 361
  • For n = 9: 5(9²) + 5(9) + 1 = 451

Therefore, the first 10 centered dodecagonal numbers are 1, 11, 31, 61, 101, 151, 211, 281, 361, and 451.

Algorithm

The algorithm to generate the first k centered dodecagonal numbers can be described as follows:

  1. Start the program.
  2. Define a function centeredDodecagonalNo(k) that takes an input parameter k.
  3. Initialize a variable result to store the calculated centered dodecagonal number.
  4. Use a loop to iterate from n = 0 to n < k:
    • Inside the loop, calculate the centered dodecagonal number using the formula: result = 5n² + 5n + 1.
    • Display the value of result.
  5. End the loop.
  6. End the function.
  7. In the main program:
    • Call the centeredDodecagonalNo(k) function with the desired value of k.
  8. End the program.

Pseudocode


centeredDodecagonalNo(k):
	result = 0
	for n = 0 to n < k:
		result = 5 * n^2 + 5 * n + 1
		display result
	end for
end function

main:
	centeredDodecagonalNo(k)
end main

  

Code Solution

Here given code implementation process.

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

void centeredDodecagonalNo(int k)
{
	int result = 0;
	// Print all initial k centered Dodecagonal number
	for (int n = 0; n < k; ++n)
	{
		// Centered dodecagonal formula =  5n²+5n+ 1
		result = ((5 *(n *n) + (5 *n) + 1));
		// Display value
		printf("  %d", result);
	}
}
int main()
{
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
	// Test 
	// k  = 10
	centeredDodecagonalNo(10);
	return 0;
}

Output

  1  11  31  61  101  151  211  281  361  451
// Java program for
// Centered Dodecagonal Number
public class DodecagonalNumber
{
	public void centeredDodecagonalNo(int k)
	{
		int result = 0;
		// Print all initial k centered dodecagonal number
		for (int n = 0; n < k; ++n)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
            
            // Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		DodecagonalNumber task = new DodecagonalNumber();
		// Centered Dodecagonal numbers
		// --------------------------------------
		// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
		// 451, 551, 661, 781, 9119 .. etc
      
		// Test 
		// k  = 10
		task.centeredDodecagonalNo(10);
	}
}

Output

 1 11 31 61 101 151 211 281 361 451
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered Dodecagonal Number

class DodecagonalNumber
{
	public: void centeredDodecagonalNo(int k)
	{
		int result = 0;
		// Print all initial k centered dodecagonal number
		for (int n = 0; n < k; ++n)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 *(n *n) + (5 *n) + 1));
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	DodecagonalNumber *task = new DodecagonalNumber();
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
  
	// Test 
	// k  = 10
	task->centeredDodecagonalNo(10);
	return 0;
}

Output

 1 11 31 61 101 151 211 281 361 451
// Include namespace system
using System;
// Csharp program for
// Centered Dodecagonal Number
public class DodecagonalNumber
{
	public void centeredDodecagonalNo(int k)
	{
		int result = 0;
		// Print all initial k centered dodecagonal number
		for (int n = 0; n < k; ++n)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		DodecagonalNumber task = new DodecagonalNumber();
		// Centered Dodecagonal numbers
		// --------------------------------------
		// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
		// 451, 551, 661, 781, 9119 .. etc
      
		// Test 
		// k  = 10
		task.centeredDodecagonalNo(10);
	}
}

Output

 1 11 31 61 101 151 211 281 361 451
package main
import "fmt"
// Go program for
// Centered Dodecagonal Number

func centeredDodecagonalNo(k int) {
	var result int = 0
	// Print all initial k centered dodecagonal number
	for n := 0 ; n < k ; n++ {
		// Centered dodecagonal 
		// formula =  5n²+5n+ 1
		// Calculate result
		result = ((5 * (n * n) + (5 * n) + 1))
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
  
	// Test 
	// k  = 10
	centeredDodecagonalNo(10)
}

Output

 1 11 31 61 101 151 211 281 361 451
<?php
// Php program for
// Centered Dodecagonal Number
class DodecagonalNumber
{
	public	function centeredDodecagonalNo($k)
	{
		$result = 0;
		// Print all initial k centered dodecagonal number
		for ($n = 0; $n < $k; ++$n)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			$result = ((5 * ($n * $n) + (5 * $n) + 1));
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new DodecagonalNumber();
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
	// Test 
	// k  = 10
	$task->centeredDodecagonalNo(10);
}
main();

Output

 1 11 31 61 101 151 211 281 361 451
// Node JS program for
// Centered Dodecagonal Number
class DodecagonalNumber
{
	centeredDodecagonalNo(k)
	{
		var result = 0;
		// Print all initial k centered dodecagonal number
		for (var n = 0; n < k; ++n)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new DodecagonalNumber();
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
  
	// Test 
	// k  = 10
	task.centeredDodecagonalNo(10);
}
main();

Output

 1 11 31 61 101 151 211 281 361 451
#  Python 3 program for
#  Centered Dodecagonal Number
class DodecagonalNumber :
	def centeredDodecagonalNo(self, k) :
		result = 0
		n = 0
		#  Print all initial k centered dodecagonal number
		while (n < k) :
			#  Centered dodecagonal 
			#  formula =  5n²+5n+ 1
            
			#  Calculate result
			result = ((5 * (n * n) + (5 * n) + 1))

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

def main() :
	task = DodecagonalNumber()
	#  Centered Dodecagonal numbers
	#  --------------------------------------
	#  1, 11, 31, 61, 101, 151, 211, 281, 361, 
	#  451, 551, 661, 781, 9119 .. etc
    
	#  Test 
	#  k  = 10
	task.centeredDodecagonalNo(10)

if __name__ == "__main__": main()

Output

  1  11  31  61  101  151  211  281  361  451
#  Ruby program for
#  Centered Dodecagonal Number
class DodecagonalNumber 
	def centeredDodecagonalNo(k) 
		result = 0
		n = 0
		#  Print all initial k centered dodecagonal number
		while (n < k) 
			#  Centered dodecagonal 
			#  formula =  5n²+5n+ 1
            
			#  Calculate result
			result = ((5 * (n * n) + (5 * n) + 1))

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

	end

end

def main() 
	task = DodecagonalNumber.new()
	#  Centered Dodecagonal numbers
	#  --------------------------------------
	#  1, 11, 31, 61, 101, 151, 211, 281, 361, 
	#  451, 551, 661, 781, 9119 .. etc
	#  Test 
	#  k  = 10
	task.centeredDodecagonalNo(10)
end

main()

Output

 1 11 31 61 101 151 211 281 361 451
// Scala program for
// Centered Dodecagonal Number
class DodecagonalNumber()
{
	def centeredDodecagonalNo(k: Int): Unit = {
		var result: Int = 0;
		var n: Int = 0;
		// Print all initial k centered dodecagonal number
		while (n < k)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: DodecagonalNumber = new DodecagonalNumber();
		// Centered Dodecagonal numbers
		// --------------------------------------
		// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
		// 451, 551, 661, 781, 9119 .. etc
		// Test 
		// k  = 10
		task.centeredDodecagonalNo(10);
	}
}

Output

 1 11 31 61 101 151 211 281 361 451
// Swift 4 program for
// Centered Dodecagonal Number
class DodecagonalNumber
{
	func centeredDodecagonalNo(_ k: Int)
	{
		var result: Int = 0;
		var n: Int = 0;
		// Print all initial k centered dodecagonal number
		while (n < k)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: DodecagonalNumber = DodecagonalNumber();
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
	// Test 
	// k  = 10
	task.centeredDodecagonalNo(10);
}
main();

Output

  1  11  31  61  101  151  211  281  361  451
// Kotlin program for
// Centered Dodecagonal Number
class DodecagonalNumber
{
	fun centeredDodecagonalNo(k: Int): Unit
	{
		var result: Int ;
		var n: Int = 0;
		// Print all initial k centered dodecagonal number
		while (n < k)
		{
			// Centered dodecagonal 
			// formula =  5n²+5n+ 1
          
			// Calculate result
			result = ((5 * (n * n) + (5 * n) + 1));
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: DodecagonalNumber = DodecagonalNumber();
	// Centered Dodecagonal numbers
	// --------------------------------------
	// 1, 11, 31, 61, 101, 151, 211, 281, 361, 
	// 451, 551, 661, 781, 9119 .. etc
  
	// Test 
	// k  = 10
	task.centeredDodecagonalNo(10);
}

Output

 1 11 31 61 101 151 211 281 361 451

Result

When we run the provided code with the input k = 10, it will generate and display the first 10 centered dodecagonal numbers: 1, 11, 31, 61, 101, 151, 211, 281, 361, and 451.

The time complexity of this code is O(k) because the loop runs k times, where k is the desired number of centered dodecagonal numbers to be generated. The calculations inside the loop have constant time complexity, so they do not affect the overall time complexity.





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