Requirements: - In C# - ONLY use Loops. No Arrays or Lists Create a program that
ID: 3732887 • Letter: R
Question
Requirements:
- In C#
- ONLY use Loops. No Arrays or Lists
Create a program that will take user's positive integer input between 1 and 50 and calculate the juggler's sequence for that number. As output, list the number, the maximum value in the sequence and the number of steps required to get to 1.
a. Take the number
b. If the number is even, raise it to 1/2 power
c. if the number is odd, raise it to 3/2 power
d. Take the resultant number through this sequence until the output is 1
e. NOTE: if you enter 37 as the input, your program will overload unless you use the System.Numberics.BigInterger Structure
Explanation / Answer
using System;
namespace MySolution
{
public class Solution
{
public static void Main(string[] args)
{
Console.Write("Enter the number : ");
int n = Convert.ToInt32(Console.ReadLine());
// count the number of steps
int steps = 0;
while(n != 1)
{
// if number is even
if( n % 2 == 0 )
n = (int)Math.Pow(n , 0.5);
// if number is odd
else
n = (int)Math.Pow(n , 1.5);
steps++;
}
Console.Write(" Number of Steps : " + steps);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.