Given the following pseudocode What is produced by its execu

Given the following pseudocode. What is produced by its execution?

a) for (i = 5; i < 10; i=i+1)

               { Display “Happy!” }

b) for (i = 5; i < 15; i=i+3)

              { Display “Happy!” }

c) n = 5

while(n < 13)

{ Display “Happy”

   n = n + 3}

Display “Stop”

d) n = 8

while(n < 24)

{ Display “Happy”

   n = n + 5}

Display “Stop”

e) n = 7

while(n < 6)

{ Display “Happy”

   n = n + 1}

Display “Stop”

Solution

problem a:
   for (i = 5; i < 10; i=i+1)
{ Display “Happy!” }
      
   Output:
   Happy!Happy!Happy!Happy!Happy!
  
   it prints 5 times Happy! using for loop
   so it iterates for loop from 5 to 10 and prints \"Happy!\"
  
problem b:
   for (i = 5; i < 15; i=i+3)
{ Display “Happy!” }


   Output:
   Happy!Happy!Happy!Happy!
  
   it prints 4 times Happy! using for loop
   so it iterates for loop from 5 to 15 with incrementation of i by 3 so i will be looped as 5,8,11,14 and prints \"Happy!\"

problem c:
   n = 5
   while(n < 13)
   { Display “Happy”
   n = n + 3}
   Display “Stop”
  
   Output:
   HappyHappyHappyStop
  
   it prints 3 times Happy and 1 time Stop using while loop
   so it iterates while loop from 5 to 13 with incrementation of n by 3 so i will be looped as 5,8,11 and prints \"Happy\"
   and after terminating the loop it prints \"Stop\"
  
problem d:
   n = 8
   while(n < 24)
   { Display “Happy”
   n = n + 5}
   Display “Stop”

   Output:
   HappyHappyHappyHappyStop
  
   it prints 4 times Happy and 1 time Stop using while loop
   so it iterates while loop from 8 to 24 with incrementation of n by 5 so i will be looped as 8,13,18,23 and prints \"Happy\"
   and after terminating the loop it prints \"Stop\"

problem e:
   n = 7
   while(n < 6)
   { Display “Happy”
   n = n + 1}
   Display “Stop”

   Output:
   Stop
  
   in while condition n < 6 where n is 7 so condition fails and prints Stop

Given the following pseudocode. What is produced by its execution? a) for (i = 5; i < 10; i=i+1) { Display “Happy!” } b) for (i = 5; i < 15; i=i+3) { Disp
Given the following pseudocode. What is produced by its execution? a) for (i = 5; i < 10; i=i+1) { Display “Happy!” } b) for (i = 5; i < 15; i=i+3) { Disp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site