Question 4: sequence Write a function sequence that accepts an number ( int ) and that prints a sequence of numbers that starts at the given number and obeys the following rules: the number 1 is the last number in the sequence (e.g stop ) if the number if even, the next number is half of it if the number is odd, the next number is one more Specifications: use a while loop print each number in the sequence one per line

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 28VE
icon
Related questions
Question

Question 4: sequence

Write a function sequence that accepts an number ( int ) and that prints a sequence of numbers that starts at the given number and obeys the following rules:

  • the number 1 is the last number in the sequence (e.g stop )
  • if the number if even, the next number is half of it
  • if the number is odd, the next number is one more

Specifications:

  • use a while loop
  • print each number in the sequence one per line

 

>>> sequence(3)
4
1
>>> sequence(4)
4
2
1
>>> sequence(17)
17
18
10
5
6
4
1
Transcribed Image Text:>>> sequence(3) 4 1 >>> sequence(4) 4 2 1 >>> sequence(17) 17 18 10 5 6 4 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 1 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT