Q BgQuestion:

      
Pupil
Karma Points: 50
Respect (80%):
posted by  Yoseph on 11/1/2009 4:47:32 PM  |  status: Closed  |  Earned Karma: 50

Algorithms

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/1/2009 at 8:00:00 PM
Question Details:
Hi Marth ! I need detail explanation and with step by step method
1. Which of the following does not print the same sequence of numbers as the others ?
 a) x 5                            b) x 4                         c) x 5
     while ( x < 6 ) do                 while  ( x < 5 ) do              repeat
           { print value of x ;                 { x x + 1;                  { print value of x ;
           x x + 1 }                        print value of x }               x x + 1 }
                                                                                             until   ( x > 6 )
  
  2. Which of the following set of instructions defines an algorithm in the formal , strict sense ?
  a) x 3 ;                    b) x 3 ;                   c)  x 3
       while  ( x < 5 ) do          while  ( x < 5 ) do          while  ( x < 5 ) do
           ( x   x )                   ( x x + 1 )                 ( x x - 1 )
Bonus Point Alert! Earn +7 additional karma points for helping this gold member.

AAnswers:

Answer Question Ask for clarification
Oracle
Karma Points: 31,937
posted by rapunzel on 11/1/2009 5:09:39 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
please rate - thanks

Hi Marth ! I need detail explanation and with step by step method
1. Which of the following does not print the same sequence of numbers as the others ?   C
 a) x 5                            b) x 4                         c) x 5
     while ( x < 6 ) do                 while  ( x < 5 ) do              repeat
           { print value of x ;                 { x x + 1;                  { print value of x ;
           x x + 1 }                        print value of x }               x x + 1 }
    will print 5                            will print 5                                  until   ( x > 6 )
                                                                                                 will print 5 & 6
  2. Which of the following set of instructions defines an algorithm in the formal , strict sense ? B
  a) x 3 ;                    b) x 3 ;                   c)  x 3
       while  ( x < 5 ) do          while  ( x < 5 ) do          while  ( x < 5 ) do
           ( x   x )                   ( x x + 1 )                 ( x x - 1 )   
 infinite loop X never changes
                                                 infinite loop since x is always <5

Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Oracle
Karma Points: 18,830
posted by Marth on 11/1/2009 5:11:36 PM  |  status: Live
Asker's Rating: Helpful   
Response Details:
1.
Let's look at the output of each possible answer:
a)
will start at 5, print 5, increment x, then break when x is 6
b) will start at 4, increment x, print 5 then break when x is 5
c) will print 5 6 then break (because it stops when x > 6 rather than when x >= 6

2.
Both a) and c) contain errors; a) does not increment x while c) decrements x.  Both create infinite loops, so b) must be the answer.


Thank you for rating my response. Feel free to PM me if you have further questions.

Java Genius

"Lois Lane is falling, accelerating at an initial rate of 32ft per second per second. Superman swoops down to save her by reaching out two arms of steel. Ms. Lane, who is now traveling at approximately 120 miles per hour, hits them, and is immediately sliced into three equal pieces." - Sheldon
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »