Numerical Methods for Engineers

Published by McGraw-Hill Science/Engineering/Math
ISBN 10: 0073401064
ISBN 13: 978-0-07340-106-5

Chapter 2 - Programming and Software - Problems - Page 49: 2.13

Answer

Subroutine BubbleFor(n, b) Implicit None !sorts an array in ascending !order using the bubble sort Integer(4)::m, i, n Logical::switch Real::a(n),b(n),dum m=n-1 Do switch = .False. Do i = 1, m If (b(i) > b(i + 1)) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = .True. End If End Do If (switch == .False.) Exit m=m-1 End Do End 2.14 Here is a flowchart for the algorithm: d b(i + 1) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = True End If Next i If switch = False Then Exit Do m=m-1 Loop End Sub

Work Step by Step

Subroutine BubbleFor(n, b) Implicit None !sorts an array in ascending !order using the bubble sort Integer(4)::m, i, n Logical::switch Real::a(n),b(n),dum m=n-1 Do switch = .False. Do i = 1, m If (b(i) > b(i + 1)) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = .True. End If End Do If (switch == .False.) Exit m=m-1 End Do End 2.14 Here is a flowchart for the algorithm: d b(i + 1) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = True End If Next i If switch = False Then Exit Do m=m-1 Loop End Sub
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.