80 likes | 210 Views
เฉลย Lab 10. Loop. จงเขียนโปรแกรมเพื่อหาค่า Min, Max, Sum, Average ของ N จำนวน โดยเลือกใช้คำสั่งการวนซ้ำที่เหมาะสม. Start. Read N. No. N>0. Print No Data. Yes. Read Score. Min = Score Max = Score Sum = Score Count = 1. No. Count<=N. Average = Sum / N. Yes. Print Min
E N D
เฉลย Lab 10 Loop
จงเขียนโปรแกรมเพื่อหาค่า Min, Max, Sum, Average ของ N จำนวน โดยเลือกใช้คำสั่งการวนซ้ำที่เหมาะสม Start Read N No N>0 Print No Data Yes Read Score Min = Score Max = Score Sum = Score Count = 1 No Count<=N Average = Sum / N Yes Print Min Print Max Print Sum Print Average Read Score No Score < Min Yes Min = Score Sum = Sum + Score No Score > Max Yes Max = Score Stop
TextBoxชื่อ txtInput PictureBoxชื่อ picOutput CommandButtonชื่อ cmdCompute CommandButtonชื่อ cmdEnd
Private Sub cmdCompute_Click() Dim N As Integer Dim score As Double Dim sum As Double Dim count As Double Dim Min As Double Dim Max As Double Dim Average As Double .... End Sub ประกาศตัวแปร
Private Sub cmdCompute_Click() ... If N > 0 Then Else End If .... End Sub Start N = Val(txtInput.Text) Read N No N>0 Print No Data Yes Read Score Min = Score Max = Score Sum = Score Count = 1 No Count<=N Average = Sum / N picOutput.Print “No Data" Yes Print Min Print Max Print Sum Print Average Read Score No Score < Min Yes Min = Score Sum = Sum + Score No Score > Max Yes Max = Score Stop
If N > 0 Then score = InputBox(“คะแนนของนักเรียนคนที่ 1") Min = score Max = score sum = score count = 1 Do While (count <= num) Loop Else picOutput.Print “No Data" End If N>0 Yes Read Score Min = Score Max = Score Sum = Score Count = 1 No Count<=N Yes Read Score No Score < Min Yes Min = Score Sum = Sum + Score No Score > Max Yes Max = Score
Do While (counter <= num) count = count + 1 score = InputBox(“คะแนนของนักเรียนคนที่" & counter) Ifscore < Min Then Min = score Else If score > Max Then Max = score End If End If sum = sum + score Loop No Count<=N Yes Count = count + 1 Read Score No Score < Min Yes Min = Score Sum = Sum + Score No Score > Max Yes Max = Score
No Count<=N Average = Sum / N Average = sum / N PicOutput.Print" Min = " & Min PicOutput.Print" Max = " & Max PicOutput.Print" Sum = " & sum PicOutput.Print" Average = " & Average Print Min Print Max Print Sum Print Average