Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
loop HELP "simple" Posted by jmed on 18 Feb 2010 at 2:08 PM
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
Report
Re: loop HELP "simple" Posted by jjasso5 on 18 Feb 2010 at 5:43 PM
x = input('Give me an integer: ');
while x ~= 1
if rem (x, 2) == 0
x = x/2
else
x = x*3 + 1
end
end
Report
Re: loop HELP "simple" Posted by jmed on 18 Feb 2010 at 5:58 PM
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
Report
Re: loop HELP "simple" Posted by jmed on 18 Feb 2010 at 5:58 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.