Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a program in C ++, using a while loop as an iterative statement. Given a positive integer N, the problem 3n + 1 consists

Make a program in C ++, using a while loop as an iterative statement.

Given a positive integer N, the problem 3n + 1 consists of determining whether it is possible to arrive at N = 1 by repeatedly applying the following operations:

If N is even, divide it by 2. If N is odd, multiply it by 3 and add 1 to it.

For example, if N starts at 26 then N takes the values 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. It is believed that it is always possible to get to 1 no matter what positive integer you start at (Collatz's Conjecture).

Write a program that calculates the number of steps it takes for N to become 1 and the largest value that N takes during the calculation.

Entry An integer N. You can assume that 1 N 1000.

Exit Two integers denoting the number of steps it takes for N to become 1 and the largest value that N takes during computation.

Example:

Entry -one -26 -27

Exit -0 1 -10 40 -111 9232

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Design a training session to maximize learning. page 296

Answered: 1 week ago

Question

Design a cross-cultural preparation program. page 300

Answered: 1 week ago