Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: using loops, need number to be an odd integer
Date: Sun, 18 Mar 2012 23:18:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <jk5qfi$jhu$1@newscl01ah.mathworks.com>
References: <jk5oc2$e0m$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1332112690 20030 172.30.248.46 (18 Mar 2012 23:18:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 18 Mar 2012 23:18:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:761389

"Marina" wrote in message <jk5oc2$e0m$1@newscl01ah.mathworks.com>...
> Hi,
> I am currently working on a homework assignment and on my last problem but I am having some trouble.
> 
> The question is:
> Write a program in a script file that finds the smallest odd integer that is divisible by 11 and whose square root is greater than 132. Use a loop in the program. The loop should start from 1 and stop when the number is found. The program prints the message “The required number is:” and then prints the number.
> 
> So far this is what I got in my script file:
> n = 1;
> while (sqrt(n)<132)||(rem(n,11)~=0)
> n = n+1;
> if rem(n,2)==1;
> n = n+1;
> end
> end
> 
> str = ['The number is: ' num2str(n)];
> disp(str);
> 
> The answer to this is 17424
> therefore I know something in the code is wrong because that is an even number not an odd number. The answer should be 17435 but I am unsure how to edit my code to get the right answer. I would appreciate any help.
> 
> Thank You
- - - - - - - - -
  All you need to have inside the while-loop is n = n+2.  Starting with n = 1, all n's will then be odd.

Roger Stafford