Skip to content
Pooja Bhatia Classes Hari Nagar
  • We teach following classes
    • Class 12
    • Class 11
    • Class 10
    • Class 9
  • Sumita Arora IP/CS Solutions
  • Jobs/Internship
Pooja Bhatia Classes Hari Nagar

sa 12 cs chapter 6

3. The hailstone sequence starting at a positive integer n is generated by following two simple rules. If n is even, the next number in the sequence is n / 2. If n is odd, the next number in the sequence is 3*n + 1. Repeating this process, the hailstone sequence gets generated. Write a recursive function hailstone(n) which prints the hailstone sequence beginning at n. Stop when the sequence reaches the number 1 (since otherwise, we would loop forever 1, 4, 2, 1, 4, 2, …)

sa 12 cs chapter 6 / PythonCSIP CS IP

def hail(n): print(n, end=” “) if n == 1: return if n%2 == 0: hail(n//2) else: hail(3*n+1) hail(7) print() hail(8) # Output 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 8 4 2 1

3. The hailstone sequence starting at a positive integer n is generated by following two simple rules. If n is even, the next number in the sequence is n / 2. If n is odd, the next number in the sequence is 3*n + 1. Repeating this process, the hailstone sequence gets generated. Write a recursive function hailstone(n) which prints the hailstone sequence beginning at n. Stop when the sequence reaches the number 1 (since otherwise, we would loop forever 1, 4, 2, 1, 4, 2, …) Read More »

3. Look at compute numbers one more time :

sa 12 cs chapter 6 / PythonCSIP CS IP

3. Look at compute numbers one more time : Read More »

Post pagination
← Previous 1 … 10 11 12 … 21 Next →
  • We teach following classes
    • Class 12
    • Class 11
    • Class 10
    • Class 9
  • Sumita Arora IP/CS Solutions
  • Jobs/Internship
  • We teach following classes
  • Sumita Arora IP/CS Solutions
  • Jobs/Internship

Copyright © 2025 Pooja Bhatia Classes Hari Nagar | Powered by Pooja Bhatia Classes Hari Nagar.