Question: Consider the function f ( n ) = n 2 if n is even 3 n + 1 if n is odd Given an initial

Consider the function
f(n)= n
2
if n is even
3n +1 if n is odd
Given an initial value for n (an integer), we set a1= n and ai = f(ai1). The stopping
value of n is the first i such that ai =1. The escape value of n is the first i such that
ai =100.
For example, if n =5 then
a1=5, a2=16, a3=8, a4=4, a5=2, a6=1
and so the stopping number is 6, and there is no escape value.
Write a function called outcome which takes as input integers n and max. If either n or max
are less than 1 it should return Please pick strictly positive integers. Otherwise it should
return either the stopping value of n or the escape value of n (whichever happens first) or
the message The process did not terminate within max steps(where max is the number
entered as the second input value).
You should use the Mod function in VBA (you may need to look this up online) and a suitable
Do While loop. Declare all variable types and include appropriate comments in your code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!