Centered octagonal number
Here given code implementation process.
// C Program for
// Centered octagonal number
#include <stdio.h>
void centeredOctagonalNo(int k)
{
// Print all initial k centered octagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
int result = ((4 *(n *n) - 4 *n + 1));
// Display Calculated value
printf(" %d", result);
}
}
int main()
{
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
centeredOctagonalNo(10);
return 0;
}
Output
1 9 25 49 81 121 169 225 289 361
// Java program for
// Centered octagonal number
public class CenteredOctagonal
{
public void centeredOctagonalNo(int k)
{
// Print all initial k centered octagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
int result = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
System.out.print(" " + result);
}
}
public static void main(String[] args)
{
CenteredOctagonal task = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
}
Output
1 9 25 49 81 121 169 225 289 361
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Centered octagonal number
class CenteredOctagonal
{
public: void centeredOctagonalNo(int k)
{
// Print all initial k centered octagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
int result = ((4 *(n *n) - 4 *n + 1));
// Display calculated result
cout << " " << result;
}
}
};
int main()
{
CenteredOctagonal *task = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task->centeredOctagonalNo(10);
return 0;
}
Output
1 9 25 49 81 121 169 225 289 361
// Include namespace system
using System;
// Csharp program for
// Centered octagonal number
public class CenteredOctagonal
{
public void centeredOctagonalNo(int k)
{
// Print all initial k centered octagonal number
for (int n = 1; n <= k; ++n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
int result = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
Console.Write(" " + result);
}
}
public static void Main(String[] args)
{
CenteredOctagonal task = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
}
Output
1 9 25 49 81 121 169 225 289 361
package main
import "fmt"
// Go program for
// Centered octagonal number
func centeredOctagonalNo(k int) {
// Print all initial k centered octagonal number
for n := 1 ; n <= k ; n++ {
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
var result int = ((4 * (n * n) - 4 * n + 1))
// Display calculated result
fmt.Print(" ", result)
}
}
func main() {
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
centeredOctagonalNo(10)
}
Output
1 9 25 49 81 121 169 225 289 361
<?php
// Php program for
// Centered octagonal number
class CenteredOctagonal
{
public function centeredOctagonalNo($k)
{
// Print all initial k centered octagonal number
for ($n = 1; $n <= $k; ++$n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
$result = ((4 * ($n * $n) - 4 * $n + 1));
// Display calculated result
echo(" ".$result);
}
}
}
function main()
{
$task = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
$task->centeredOctagonalNo(10);
}
main();
Output
1 9 25 49 81 121 169 225 289 361
// Node JS program for
// Centered octagonal number
class CenteredOctagonal
{
centeredOctagonalNo(k)
{
// Print all initial k centered octagonal number
for (var n = 1; n <= k; ++n)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
var result = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
process.stdout.write(" " + result);
}
}
}
function main()
{
var task = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
main();
Output
1 9 25 49 81 121 169 225 289 361
# Python 3 program for
# Centered octagonal number
class CenteredOctagonal :
def centeredOctagonalNo(self, k) :
n = 1
# Print all initial k centered octagonal number
while (n <= k) :
# Formula
# (4n² - 4n + 1)
# Calculate nth octagonal number
result = ((4 * (n * n) - 4 * n + 1))
# Display calculated result
print(" ", result, end = "")
n += 1
def main() :
task = CenteredOctagonal()
# Centered octagonal numbers are
# —————————————————————————————————————————————
# 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
# 441, 529, 625, 729, 841, 961 ... etc
# Test k = 10
task.centeredOctagonalNo(10)
if __name__ == "__main__": main()
Output
1 9 25 49 81 121 169 225 289 361
# Ruby program for
# Centered octagonal number
class CenteredOctagonal
def centeredOctagonalNo(k)
n = 1
# Print all initial k centered octagonal number
while (n <= k)
# Formula
# (4n² - 4n + 1)
# Calculate nth octagonal number
result = ((4 * (n * n) - 4 * n + 1))
# Display calculated result
print(" ", result)
n += 1
end
end
end
def main()
task = CenteredOctagonal.new()
# Centered octagonal numbers are
# —————————————————————————————————————————————
# 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
# 441, 529, 625, 729, 841, 961 ... etc
# Test k = 10
task.centeredOctagonalNo(10)
end
main()
Output
1 9 25 49 81 121 169 225 289 361
// Scala program for
// Centered octagonal number
class CenteredOctagonal()
{
def centeredOctagonalNo(k: Int): Unit = {
var n: Int = 1;
// Print all initial k centered octagonal number
while (n <= k)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
var result: Int = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
print(" " + result);
n += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: CenteredOctagonal = new CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
}
Output
1 9 25 49 81 121 169 225 289 361
// Swift 4 program for
// Centered octagonal number
class CenteredOctagonal
{
func centeredOctagonalNo(_ k: Int)
{
var n: Int = 1;
// Print all initial k centered octagonal number
while (n <= k)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
let result: Int = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
print(" ", result, terminator: "");
n += 1;
}
}
}
func main()
{
let task: CenteredOctagonal = CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
main();
Output
1 9 25 49 81 121 169 225 289 361
// Kotlin program for
// Centered octagonal number
class CenteredOctagonal
{
fun centeredOctagonalNo(k: Int): Unit
{
var n: Int = 1;
// Print all initial k centered octagonal number
while (n <= k)
{
// Formula
// (4n² - 4n + 1)
// Calculate nth octagonal number
val result: Int = ((4 * (n * n) - 4 * n + 1));
// Display calculated result
print(" " + result);
n += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
val task: CenteredOctagonal = CenteredOctagonal();
// Centered octagonal numbers are
// —————————————————————————————————————————————
// 1, 9, 25, 49, 81, 121, 169, 225, 289, 361
// 441, 529, 625, 729, 841, 961 ... etc
// Test k = 10
task.centeredOctagonalNo(10);
}
Output
1 9 25 49 81 121 169 225 289 361
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