What is the output of the following pseudocode? count: 0 For i = 1 to 4 For ji+ 1 to 5 End-for End-for Return(count) count: count + i*j

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question
Question 2
What is the output of the following pseudocode?
count := 0
For i = 1 to 4
For j = i + 1 to 5
count
End-for
End-for
Return(count)
count+i*j
Transcribed Image Text:Question 2 What is the output of the following pseudocode? count := 0 For i = 1 to 4 For j = i + 1 to 5 count End-for End-for Return(count) count+i*j
Expert Solution
Explanation

We have a pseudocode in question which uses a nested for loop. Below are details 

  • It initialize count variable as 0
  • It runs an outer for loop from i = 1 to 4. This will run for loop for value of i = 1, 2, 3.
    • It runs inner for loop from j = i to 5.
      • This will run for loop for value of j = 2, 3, 4 when i = 1
        • it accumulate sum of product of i and j in count variable
        • count = count + i*j
        • 2   = 0   + 1*2
        • 5   = 2   + 1*3
        • 9   = 5   + 1* 4
      • This will run for loop for value of j = 3, 4 when i = 2
        • it accumulate sum of product of i and j in count variable
        • count = count + i*j
        • 15 = 9   + 2*3
        • 23 = 15 + 2*4
      • This will run for loop for value of j = 4 when i = 3
        • it accumulate sum of product of i and j in count variable
        • count = count + i*j
        • 35  = 23+ 3*4
  • return value of count(35)
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,