Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question: Ulam's Conjecture states that if you start off with a positive integer and form a series of numbers as follows: If the number is
Question: Ulam's Conjecture states that if you start off with a positive integer and form a series of numbers as follows: If the number is even, divide it by 2 If the number is odd. multiply it by 3 and add 1 then the sequence will always become a 1 at some stage, e.g. the sequence for a number starting at 6 is: 6:3; 10;5; 16; 8: 4:2:1 Write a program that asks the user to input a number N and the program must print the Ulam Sequence which terminates when a 1 is generated. Also use a method for repeating the program if the user selects y if asked to continue. The user should be able to enter either an uppercase or lowercase response. Create and use a function CalcNextulam in the above program that will calculate the next Ulam number based on an input value. The usage of the function should be as follows: newval - CalcNextulam (val); Hint: First make sure the program works and that you get the correct results without using the CalcNextUlam function. Only when you are sure that everything is correct, then try to change the code to work with the calcNextUlam function. Sample: Enter initial Ulam value: 3 Sequence is 3; 10 ; 5; 16; 8 ; 4 ; 2; 1 Do you want to continue (y)? y Enter initial Ulam value: 6 Sequence is 6:3; 10 ; 5; 16; 8; 4; 2; 1 Do you want to continue (y)? Y Enter initial Ulam value: 20 Sequence is 20 ; 10 ; 5; 16; 8; 4; 2; 1 Do you want to continue (y)? n Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started