Skip to main content

Find star number

Here given code implementation process.

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

void starNo(int k)
{
	// Print all initial k star number
	for (int n = 1; n <= k; ++n)
	{
		// Formula
		//   6n(n − 1) + 1
      
		// Calculate nth star number
		int result = (6 *n *(n - 1) + 1);
      
		// Display calculated result
		printf("  %d", result);
	}
}
int main()
{
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
    // 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	starNo(10);
	return 0;
}

Output

  1  13  37  73  121  181  253  337  433  541
// Java program for
// Find star number
public class StarNumber
{
	public void starNo(int k)
	{
		// Print all initial k star number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			int result = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			System.out.print(" " + result);
		}
	}
	public static void main(String[] args)
	{
		StarNumber task = new StarNumber();
		// Star number are
		// —————————————————————————————————————————————
		// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
		// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
		// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
		// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
		// k = 10
		task.starNo(10);
	}
}

Output

 1 13 37 73 121 181 253 337 433 541
// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Find star number

class StarNumber
{
	public: void starNo(int k)
	{
		// Print all initial k star number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			int result = (6 *n *(n - 1) + 1);
          
			// Display calculated result
			cout << " " << result;
		}
	}
};
int main()
{
	StarNumber *task = new StarNumber();
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	task->starNo(10);
	return 0;
}

Output

 1 13 37 73 121 181 253 337 433 541
// Include namespace system
using System;
// Csharp program for
// Find star number
public class StarNumber
{
	public void starNo(int k)
	{
		// Print all initial k star number
		for (int n = 1; n <= k; ++n)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			int result = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			Console.Write(" " + result);
		}
	}
	public static void Main(String[] args)
	{
		StarNumber task = new StarNumber();
		// Star number are
		// —————————————————————————————————————————————
		// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
		// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
		// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
		// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
      
		// k = 10
		task.starNo(10);
	}
}

Output

 1 13 37 73 121 181 253 337 433 541
package main
import "fmt"
// Go program for
// Find star number

func starNo(k int) {
	// Print all initial k star number
	for n := 1 ; n <= k ; n++ {
		// Formula
		// 6n(n − 1) + 1
		// Calculate nth star number
		var result int = (6 * n * (n - 1) + 1)
		// Display calculated result
		fmt.Print(" ", result)
	}
}
func main() {
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	starNo(10)
}

Output

 1 13 37 73 121 181 253 337 433 541
<?php
// Php program for
// Find star number
class StarNumber
{
	public	function starNo($k)
	{
		// Print all initial k star number
		for ($n = 1; $n <= $k; ++$n)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			$result = (6 * $n * ($n - 1) + 1);
          
			// Display calculated result
			echo(" ".$result);
		}
	}
}

function main()
{
	$task = new StarNumber();
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	$task->starNo(10);
}
main();

Output

 1 13 37 73 121 181 253 337 433 541
// Node JS program for
// Find star number
class StarNumber
{
	starNo(k)
	{
		// Print all initial k star number
		for (var n = 1; n <= k; ++n)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			var result = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			process.stdout.write(" " + result);
		}
	}
}

function main()
{
	var task = new StarNumber();
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	task.starNo(10);
}
main();

Output

 1 13 37 73 121 181 253 337 433 541
#  Python 3 program for
#  Find star number
class StarNumber :
	def starNo(self, k) :
		n = 1
		#  Print all initial k star number
		while (n <= k) :
			#  Formula
			#  6n(n − 1) + 1
            
			#  Calculate nth star number
			result = (6 * n * (n - 1) + 1)

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

def main() :
	task = StarNumber()
	#  Star number are
	#  —————————————————————————————————————————————
	#  1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	#  793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	#  2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	#  4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
    
	#  k = 10
	task.starNo(10)

if __name__ == "__main__": main()

Output

  1  13  37  73  121  181  253  337  433  541
#  Ruby program for
#  Find star number
class StarNumber 
	def starNo(k) 
		n = 1
		#  Print all initial k star number
		while (n <= k) 
			#  Formula
			#  6n(n − 1) + 1
            
			#  Calculate nth star number
			result = (6 * n * (n - 1) + 1)

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

	end

end

def main() 
	task = StarNumber.new()
	#  Star number are
	#  —————————————————————————————————————————————
	#  1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	#  793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	#  2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	#  4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
    
	#  k = 10
	task.starNo(10)
end

main()

Output

 1 13 37 73 121 181 253 337 433 541
// Scala program for
// Find star number
class StarNumber()
{
	def starNo(k: Int): Unit = {
		var n: Int = 1;
		// Print all initial k star number
		while (n <= k)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			var result: Int = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: StarNumber = new StarNumber();
		// Star number are
		// —————————————————————————————————————————————
		// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
		// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
		// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
		// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
		// k = 10
		task.starNo(10);
	}
}

Output

 1 13 37 73 121 181 253 337 433 541
// Swift 4 program for
// Find star number
class StarNumber
{
	func starNo(_ k: Int)
	{
		var n: Int = 1;
		// Print all initial k star number
		while (n <= k)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			let result: Int = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			print(" ", result, terminator: "");
			n += 1;
		}
	}
}
func main()
{
	let task: StarNumber = StarNumber();
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
  
	// k = 10
	task.starNo(10);
}
main();

Output

  1  13  37  73  121  181  253  337  433  541
// Kotlin program for
// Find star number
class StarNumber
{
	fun starNo(k: Int): Unit
	{
		var n: Int = 1;
		// Print all initial k star number
		while (n <= k)
		{
			// Formula
			// 6n(n − 1) + 1
          
			// Calculate nth star number
			val result: Int = (6 * n * (n - 1) + 1);
          
			// Display calculated result
			print(" " + result);
			n += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: StarNumber = StarNumber();
	// Star number are
	// —————————————————————————————————————————————
	// 1, 13, 37, 73, 121, 181, 253, 337, 433, 541, 661, 
	// 793, 937, 1093, 1261, 1441, 1633, 1837, 2053, 2281, 
	// 2521, 2773, 3037, 3313, 3601, 3901, 4213, 4537, 
	// 4873, 5221, 5581, 5953, 6337, 6733, 7141 ... etc
	// k = 10
	task.starNo(10);
}

Output

 1 13 37 73 121 181 253 337 433 541




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