Question

Consider a sequence of integers that is constructed in the following manner:

Start with any positive integer as the only term in the sequence
While the last term in the sequence is not equal to 1 do
If the last term is even then
Add another term to the sequence by dividing the last term by 2 using
floor division
Else
Add another term to the sequence by multiplying the last term by 3 and
adding 1

'''(what you see above is how we write pseudo code for algorithms, more like the thought process for
writing the actual code)'''

The Collatz conjecture states that this sequence will eventually end with one when it begins with any positive integer. Although this conjecture has never been proved, it appears to be true. Create a program that reads an integer, n, from the user and reports all of the values in the sequence starting with n and ending with one. Your program should allow the user to continue entering new n values (and your program should continue displaying the sequences) until the user enters a value for n that is less than or equal to zero.

The Collatz conjecture is an example of an open problem in mathematics. While many people have tried to prove that it is true, no one has been able to do so. Information on other open problems in mathematics can be found on the Internet. https://www.youtube.com/watch?v=094y1Z2wpJg

Question

Write a program that converts a decimal (base 10) number to binary (base 2). Read the decimal number from the user as an integer and then use the division algorithm shown below to perform the conversion. When the algorithm completes, the result contains the binary representation of the number. Display the result, along with an appropriate message.

Let result be an empty string
Let q represent the number to convert
repeat
Set r equal to the remainder when q is divided by 2
Convert r to a string and add it to the beginning of result
Divide q by 2, discarding any remainder, and store the result back into q
until q is 0

Question

Write a function that takes the lengths of the two shorter sides of a right triangle as its parameters. Return the hypotenuse of the triangle, computed using the Pythagorean theorem, as the function’s result. Include the main program that reads the lengths of the shorter sides of a right triangle from the user, uses your function to compute the length of the hypotenuse, and displays the result.