Number of hamiltonian cycles in a complete graph

Here given code implementation process.

// C Program
// Number of hamiltonian cycles in a complete graph
#include <stdio.h>

void hamiltonianCycle(int node)
{
	int count = 1;
	int i = node - 1;
	// Calculate factorial
	while (i > 0)
	{
		count = count *i;
		i--;
	}
	// Display number of nodes
	printf("\n Number of node : %d", node);
	// Display calculated result
	printf("\n hamiltonian Cycle : %d", (count / 2));
}
int main()
{
	// Test
	hamiltonianCycle(6);
	hamiltonianCycle(7);
	hamiltonianCycle(4);
	return 0;
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Java Program 
// Number of hamiltonian cycles in a complete graph
public class Cycle
{
	public void hamiltonianCycle(int node)
	{
		int count = 1;
		int i = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i--;
		}
		// Display number of nodes
		System.out.print("\n Number of node : " + node);
		// Display calculated result
		System.out.print("\n hamiltonian Cycle : " + (count / 2));
	}
	public static void main(String[] args)
	{
		Cycle task = new Cycle();
		// Test
		task.hamiltonianCycle(6);
		task.hamiltonianCycle(7);
		task.hamiltonianCycle(4);
	}
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Include header file
#include <iostream>
using namespace std;
// C++ Program 
// Number of hamiltonian cycles in a complete graph
class Cycle
{
	public: void hamiltonianCycle(int node)
	{
		int count = 1;
		int i = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count *i;
			i--;
		}
		// Display number of nodes
		cout << "\n Number of node : " << node;
		// Display calculated result
		cout << "\n hamiltonian Cycle : " << (count / 2);
	}
};
int main()
{
	Cycle *task = new Cycle();
	// Test
	task->hamiltonianCycle(6);
	task->hamiltonianCycle(7);
	task->hamiltonianCycle(4);
	return 0;
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Include namespace system
using System;
// Csharp Program 
// Number of hamiltonian cycles in a complete graph
public class Cycle
{
	public void hamiltonianCycle(int node)
	{
		int count = 1;
		int i = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i--;
		}
		// Display number of nodes
		Console.Write("\n Number of node : " + node);
		// Display calculated result
		Console.Write("\n hamiltonian Cycle : " + (count / 2));
	}
	public static void Main(String[] args)
	{
		Cycle task = new Cycle();
		// Test
		task.hamiltonianCycle(6);
		task.hamiltonianCycle(7);
		task.hamiltonianCycle(4);
	}
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
package main
import "fmt"
// Go Program 
// Number of hamiltonian cycles in a complete graph

func hamiltonianCycle(node int) {
	var count int = 1
	var i int = node - 1
	// Calculate factorial
	for (i > 0) {
		count = count * i
		i--
	}
	// Display number of nodes
	fmt.Print("\n Number of node : ", node)
	// Display calculated result
	fmt.Print("\n hamiltonian Cycle : ", (count / 2))
}
func main() {

	// Test
	hamiltonianCycle(6)
	hamiltonianCycle(7)
	hamiltonianCycle(4)
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
<?php
// Php Program 
// Number of hamiltonian cycles in a complete graph
class Cycle
{
	public	function hamiltonianCycle($node)
	{
		$count = 1;
		$i = $node - 1;
		// Calculate factorial
		while ($i > 0)
		{
			$count = $count * $i;
			$i--;
		}
		// Display number of nodes
		echo("\n Number of node : ".$node);
		// Display calculated result
		echo("\n hamiltonian Cycle : ".((int)($count / 2)));
	}
}

function main()
{
	$task = new Cycle();
	// Test
	$task->hamiltonianCycle(6);
	$task->hamiltonianCycle(7);
	$task->hamiltonianCycle(4);
}
main();

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Node JS Program 
// Number of hamiltonian cycles in a complete graph
class Cycle
{
	hamiltonianCycle(node)
	{
		var count = 1;
		var i = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i--;
		}
		// Display number of nodes
		process.stdout.write("\n Number of node : " + node);
		// Display calculated result
		process.stdout.write("\n hamiltonian Cycle : " + (parseInt(count / 2)));
	}
}

function main()
{
	var task = new Cycle();
	// Test
	task.hamiltonianCycle(6);
	task.hamiltonianCycle(7);
	task.hamiltonianCycle(4);
}
main();

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
#  Python 3 Program 
#  Number of hamiltonian cycles in a complete graph
class Cycle :
	def hamiltonianCycle(self, node) :
		count = 1
		i = node - 1
		#  Calculate factorial
		while (i > 0) :
			count = count * i
			i -= 1
		
		#  Display number of nodes
		print("\n Number of node : ", node, end = "")
		#  Display calculated result
		print("\n hamiltonian Cycle : ", (int(count / 2)), end = "")
	

def main() :
	task = Cycle()
	#  Test
	task.hamiltonianCycle(6)
	task.hamiltonianCycle(7)
	task.hamiltonianCycle(4)

if __name__ == "__main__": main()

Output

 Number of node :  6
 hamiltonian Cycle :  60
 Number of node :  7
 hamiltonian Cycle :  360
 Number of node :  4
 hamiltonian Cycle :  3
#  Ruby Program 
#  Number of hamiltonian cycles in a complete graph
class Cycle 
	def hamiltonianCycle(node) 
		count = 1
		i = node - 1
		#  Calculate factorial
		while (i > 0) 
			count = count * i
			i -= 1
		end

		#  Display number of nodes
		print("\n Number of node : ", node)
		#  Display calculated result
		print("\n hamiltonian Cycle : ", (count / 2))
	end

end

def main() 
	task = Cycle.new()
	#  Test
	task.hamiltonianCycle(6)
	task.hamiltonianCycle(7)
	task.hamiltonianCycle(4)
end

main()

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Scala Program 
// Number of hamiltonian cycles in a complete graph
class Cycle()
{
	def hamiltonianCycle(node: Int): Unit = {
		var count: Int = 1;
		var i: Int = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i -= 1;
		}
		// Display number of nodes
		print("\n Number of node : " + node);
		// Display calculated result
		print("\n hamiltonian Cycle : " + (count / 2));
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Cycle = new Cycle();
		// Test
		task.hamiltonianCycle(6);
		task.hamiltonianCycle(7);
		task.hamiltonianCycle(4);
	}
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3
// Swift 4 Program 
// Number of hamiltonian cycles in a complete graph
class Cycle
{
	func hamiltonianCycle(_ node: Int)
	{
		var count: Int = 1;
		var i: Int = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i -= 1;
		}
		// Display number of nodes
		print("\n Number of node : ", node, terminator: "");
		// Display calculated result
		print("\n hamiltonian Cycle : ", (count / 2), terminator: "");
	}
}
func main()
{
	let task: Cycle = Cycle();
	// Test
	task.hamiltonianCycle(6);
	task.hamiltonianCycle(7);
	task.hamiltonianCycle(4);
}
main();

Output

 Number of node :  6
 hamiltonian Cycle :  60
 Number of node :  7
 hamiltonian Cycle :  360
 Number of node :  4
 hamiltonian Cycle :  3
// Kotlin Program 
// Number of hamiltonian cycles in a complete graph
class Cycle
{
	fun hamiltonianCycle(node: Int): Unit
	{
		var count: Int = 1;
		var i: Int = node - 1;
		// Calculate factorial
		while (i > 0)
		{
			count = count * i;
			i -= 1;
		}
		// Display number of nodes
		print("\n Number of node : " + node);
		// Display calculated result
		print("\n hamiltonian Cycle : " + (count / 2));
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Cycle = Cycle();
	// Test
	task.hamiltonianCycle(6);
	task.hamiltonianCycle(7);
	task.hamiltonianCycle(4);
}

Output

 Number of node : 6
 hamiltonian Cycle : 60
 Number of node : 7
 hamiltonian Cycle : 360
 Number of node : 4
 hamiltonian Cycle : 3


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