Menu

[solved] – Question 75071

Write a C program that reads 10 integers (between 0-1000) into a one-dimensional array
and computes and finds the value that has the largest chain. You should compute the
largest chain as explained below.
Example:
For each value (n) in your array, your chain will be determined as follows;
If n is even -> n=n/2
If n is odd -> n=3n+1
For example , if 12 is your starting number , the chain will be ,
6 -> 3 -> 10 -> 5 ->16 -> 8 -> 4 -> 2 -> 1
12 is even so 12/2 will be 6.
6 is even 6/3 will be 3.
3 is odd 3*3+1 will be 10.
.
.
.
The chain will grow until the value is 1.
Write a function called findLargestChain() that accepts an integer, finds and prints the
chain elements to the screen , and returns the number of elements.
You should store the number of elements into another array.
In the main program, you should read 10 integers into an array , call the function for each
integer and store the number of elements into another array.

Expert Answer


OR


Leave a Reply

Your email address will not be published. Required fields are marked *