Juggler Sequence

Here given code implementation process.

// C Program for
// Juggler Sequence
#include <stdio.h>
#include <math.h>

void jugglerSequence(int n)
{
	if (n <= 1)
	{
		return;
	}
	printf("\n Juggler Sequence start with %d is \n", n);
	int value = n;
	while (value > 1)
	{
		printf(" %d", value);
		if ((value % 2) == 0)
		{
			// When value is even
			/*
			    formula
			    ----------
			    v^(1/2) = v ^ (0.5)
			*/
			value = floor(pow(value, 0.5));
		}
		else
		{
			// When value is odd
			/*
			    formula
			    ----------
			    v^(3.0/2.0) = v ^ (1.5)
			*/
			value = floor(pow(value, 1.5));
		}
	}
  	// Last element
	printf(" 1\n");
}
int main()
{
	// Test
	jugglerSequence(10);
	jugglerSequence(5);
	return 0;
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
// Java program for
// Juggler Sequence
public class Sequence
{
	public void jugglerSequence(int n)
	{
		if (n <= 1)
		{
			return;
		}
		System.out.print("\n Juggler Sequence start with " + n + " is \n");
		int value = n;
		while (value > 1)
		{
			System.out.print(" " + value);
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = (int)Math.floor(Math.pow(value, 0.5));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = (int)Math.floor(Math.pow(value, 1.5));
			}
		}
		// Last element
		System.out.print(" 1\n");
	}
	public static void main(String[] args)
	{
		Sequence task = new Sequence();
		// Test
		task.jugglerSequence(10);
		task.jugglerSequence(5);
	}
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
// Include header file
#include <iostream>

#include <math.h>

using namespace std;
// C++ program for
// Juggler Sequence
class Sequence
{
	public: void jugglerSequence(int n)
	{
		if (n <= 1)
		{
			return;
		}
		cout << "\n Juggler Sequence start with " << n << " is \n";
		int value = n;
		while (value > 1)
		{
			cout << " " << value;
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = (int) floor(pow(value, 0.5));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = (int) floor(pow(value, 1.5));
			}
		}
		// Last element
		cout << " 1\n";
	}
};
int main()
{
	Sequence *task = new Sequence();
	// Test
	task->jugglerSequence(10);
	task->jugglerSequence(5);
	return 0;
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
// Include namespace system
using System;
// Csharp program for
// Juggler Sequence
public class Sequence
{
	public void jugglerSequence(int n)
	{
		if (n <= 1)
		{
			return;
		}
		Console.Write("\n Juggler Sequence start with " + n + " is \n");
		int value = n;
		while (value > 1)
		{
			Console.Write(" " + value);
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = (int) Math.Floor(Math.Pow(value, 0.5));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = (int) Math.Floor(Math.Pow(value, 1.5));
			}
		}
		// Last element
		Console.Write(" 1\n");
	}
	public static void Main(String[] args)
	{
		Sequence task = new Sequence();
		// Test
		task.jugglerSequence(10);
		task.jugglerSequence(5);
	}
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
package main
import "math"
import "fmt"
// Go program for
// Juggler Sequence

func jugglerSequence(n int) {
	if n <= 1 {
		return
	}
	fmt.Print("\n Juggler Sequence start with ", n, " is \n")
	var value int = n
	for (value > 1) {
		fmt.Print(" ", value)
		if (value % 2) == 0 {
			// When value is even
			/*
			    formula
			    ----------
			    v^(1/2) = v ^ (0.5)
			*/
			value = int(math.Floor(math.Pow(float64(value), 0.5)))
		} else {
			// When value is odd
			/*
			    formula
			    ----------
			    v^(3.0/2.0) = v ^ (1.5)
			*/
			value = int(math.Floor(math.Pow(float64(value), 1.5)))
		}
	}
	// Last element
	fmt.Print(" 1\n")
}
func main() {
	
	// Test
	jugglerSequence(10)
	jugglerSequence(5)
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
<?php
// Php program for
// Juggler Sequence
class Sequence
{
	public	function jugglerSequence($n)
	{
		if ($n <= 1)
		{
			return;
		}
		echo("\n Juggler Sequence start with ".$n.
			" is \n");
		$value = $n;
		while ($value > 1)
		{
			echo(" ".$value);
			if (($value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				$value = (int) floor(pow($value, 0.5));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				$value = (int) floor(pow($value, 1.5));
			}
		}
		// Last element
		echo(" 1\n");
	}
}

function main()
{
	$task = new Sequence();
	// Test
	$task->jugglerSequence(10);
	$task->jugglerSequence(5);
}
main();

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
// Node JS program for
// Juggler Sequence
class Sequence
{
	jugglerSequence(n)
	{
		if (n <= 1)
		{
			return;
		}
		process.stdout.write("\n Juggler Sequence start with " + 
                             n + " is \n");
		var value = n;
		while (value > 1)
		{
			process.stdout.write(" " + value);
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value =  Math.floor(Math.pow(value, 0.5));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = Math.floor(Math.pow(value, 1.5));
			}
		}
		// Last element
		process.stdout.write(" 1\n");
	}
}

function main()
{
	var task = new Sequence();
	// Test
	task.jugglerSequence(10);
	task.jugglerSequence(5);
}
main();

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
import math
#  Python 3 program for
#  Juggler Sequence
class Sequence :
	def jugglerSequence(self, n) :
		if (n <= 1) :
			return
		
		print("\n Juggler Sequence start with ", n ," is ")
		value = n
		while (value > 1) :
			print(" ", value, end = "")
			if ((value % 2) == 0) :
				#  When value is even
				#    formula
				#    ----------
				#    v^(1/2) = v ^ (0.5)
				value = math.floor(value ** 0.5)
			else :
				#  When value is odd
				#    formula
				#    ----------
				#    v^(3.0/2.0) = v ^ (1.5)
				value =  math.floor(value ** 1.5)
			
		
		#  Last element
		print(" 1")
	

def main() :
	task = Sequence()
	#  Test
	task.jugglerSequence(10)
	task.jugglerSequence(5)

if __name__ == "__main__": main()

Output

 Juggler Sequence start with  10  is
  10  3  5  11  36  6  2 1

 Juggler Sequence start with  5  is
  5  11  36  6  2 1
#  Ruby program for
#  Juggler Sequence
class Sequence 
	def jugglerSequence(n) 
		if (n <= 1) 
			return
		end

		print("\n Juggler Sequence start with ", n ," is \n")
		value = n
		while (value > 1) 
			print(" ", value)
			if ((value % 2) == 0) 
				#  When value is even
				#    formula
				#    ----------
				#    v^(1/2) = v ^ (0.5)
				value = (value ** 0.5).floor()
			else
 
				#  When value is odd
				#    formula
				#    ----------
				#    v^(3.0/2.0) = v ^ (1.5)
				value = (value ** 1.5).floor()
			end

		end

		#  Last element
		print(" 1\n")
	end

end

def main() 
	task = Sequence.new()
	#  Test
	task.jugglerSequence(10)
	task.jugglerSequence(5)
end

main()

Output

 Juggler Sequence start with 10 is 
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is 
 5 11 36 6 2 1
// Scala program for
// Juggler Sequence
class Sequence()
{
	def jugglerSequence(n: Int): Unit = {
		if (n <= 1)
		{
			return;
		}
		print("\n Juggler Sequence start with " + n + " is \n");
		var value: Int = n;
		while (value > 1)
		{
			print(" " + value);
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = Math.floor(Math.pow(value, 0.5)).toInt;
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = Math.floor(Math.pow(value, 1.5)).toInt;
			}
		}
		// Last element
		print(" 1\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Sequence = new Sequence();
		// Test
		task.jugglerSequence(10);
		task.jugglerSequence(5);
	}
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1
import Foundation;
// Swift 4 program for
// Juggler Sequence
class Sequence
{
	func jugglerSequence(_ n: Int)
	{
		if (n <= 1)
		{
			return;
		}
		print("\n Juggler Sequence start with ", n ," is ");
		var value: Int = n;
		while (value > 1)
		{
			print(" ", value, terminator: "");
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = Int(floor(pow(Double(value), 0.5)));
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = Int(floor(pow(Double(value), 1.5)));
			}
		}
		// Last element
		print(" 1");
	}
}
func main()
{
	let task: Sequence = Sequence();
	// Test
	task.jugglerSequence(10);
	task.jugglerSequence(5);
}
main();

Output

 Juggler Sequence start with  10  is
  10  3  5  11  36  6  2 1

 Juggler Sequence start with  5  is
  5  11  36  6  2 1
// Kotlin program for
// Juggler Sequence
class Sequence
{
	fun jugglerSequence(n: Int): Unit
	{
		if (n <= 1)
		{
			return;
		}
		print("\n Juggler Sequence start with " + n + " is \n");
		var value: Int = n;
		while (value > 1)
		{
			print(" " + value);
			if ((value % 2) == 0)
			{
				// When value is even
				/*
				    formula
				    ----------
				    v^(1/2) = v ^ (0.5)
				*/
				value = Math.floor(Math.pow(value.toDouble(), 0.5)).toInt();
			}
			else
			{
				// When value is odd
				/*
				    formula
				    ----------
				    v^(3.0/2.0) = v ^ (1.5)
				*/
				value = Math.floor(Math.pow(value.toDouble(), 1.5)).toInt();
			}
		}
		// Last element
		print(" 1\n");
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Sequence = Sequence();
	// Test
	task.jugglerSequence(10);
	task.jugglerSequence(5);
}

Output

 Juggler Sequence start with 10 is
 10 3 5 11 36 6 2 1

 Juggler Sequence start with 5 is
 5 11 36 6 2 1


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