loop HELP "simple" - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

loop HELP "simple"

jmedjmed Posts: 9Member
Generate a sequence of numbers. Start with integer n. If n is even divide by 2. If n is odd, multiply by 3 and add 1. Repeat process with new value of n terminating when n = 1.

Ex. n = 11 would produce

11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

Comments

  • jjasso5jjasso5 Posts: 41Member
    x = input('Give me an integer: ');
    while x ~= 1
    if rem (x, 2) == 0
    x = x/2
    else
    x = x*3 + 1
    end
    end
  • jmedjmed Posts: 9Member
    It also says to save the generated sequence of numbers into a vector named seq. Display the variable seq.

    EX:

    >>project5
    n = 3

    seq =

    3 10 5 16 8 4 2 1
  • jmedjmed Posts: 9Member
    It also says to save the generated sequence of numbers into a vector named seq. Display the variable seq.

    EX:

    >>project5
    n = 3

    seq =

    3 10 5 16 8 4 2 1
Sign In or Register to comment.