161k views
3 votes
Consider the following code that accepts two positive integer numbers as inputs.

read x, y
Result 1= 1
Result 2 = 1
counter = 1
repeat
result 1= result 1*x
counter = counter + 1
Until (counter > y)
counter = x
Do while (counter > 0)
result 2= result 2*y
counter = counter - 1
End Do
If (result 1 > result 2)
then print "x^y is greater than y^x"
else print "y^x is greater than x^y"
End if
End
42. Assume that the program graph for the above program includes every statement, including the dummy statements such as 'End If' and 'End', as separate nodes.
How many nodes are in the program graph ?
a. 16
b. 17
c. 18
d. 19
e. None of the above

1 Answer

3 votes

The answer is (c) 18.

The program graph for the given program includes the following nodes:

  1. Read x, y
  2. Result 1 = 1
  3. Result 2 = 1
  4. Counter = 1
  5. Repeat
  6. Result 1 = result 1 · x
  7. Counter + 1
  8. Until (counter > y)
  9. Counter = x
  10. Do while (counter > 0)
  11. Result 2 = result 2 · y
  12. Counter = counter – 1
  13. End Do
  14. If (result 1 > result 2)
  15. tThen print “x^y is greater than y^x”
  16. Else, print “y^x is greater than x^y”
  17. End if
  18. End

Therefore, there are a total of 18 nodes in the program graph.

User Crowie
by
8.0k points

No related questions found