Help needed

This is a discussion on Help needed within the C Programming forums, part of the General Programming Boards category; I am confused on how to solve this?? Let n 0 be a given positive integer. For i = 0, ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    1

    Help needed

    I am confused on how to solve this??

    Let n0 be a given positive integer. For i = 0, 1, 2, ... define
    if ni is even, then ni+1 = ni/2
    if ni is odd, then ni+1 = 3ni + 1
    if ni is 1, the sequence ends

    Numbers that are generated this way are called hailstones. Write a program that generates some hailstones. Your program should use the function
    void hailstones(int n);

    to compute and print the sequence generated by n. The output of your program might look as follows:

    Hailstones generated by 77:
    77 232 116 58 29 88
    44 22 11 34 17 52
    26 13 40 20 10 5
    16 8 4 2 1
    Number of hailstones generated : 23

    You might find that all the sequences you generate are finite. Whether this is true in general is still an open question. Hint: Use variables of type long instead of int if the program misbehaves.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,497
    Collatz conjecture - Wikipedia, the free encyclopedia
    Everything you need to understand the problem is there
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed with a HW
    By xkohtax in forum C Programming
    Replies: 1
    Last Post: 10-29-2009, 07:03 PM
  2. help needed again
    By Vikramnb in forum C++ Programming
    Replies: 7
    Last Post: 01-09-2009, 01:03 PM
  3. Help needed
    By Noxir in forum C++ Programming
    Replies: 16
    Last Post: 08-05-2004, 08:00 PM
  4. Some Help Needed!
    By ob1cnobe in forum C++ Programming
    Replies: 7
    Last Post: 05-29-2002, 03:08 PM
  5. changes needed!
    By Megatron in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 03-11-2002, 08:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21