1 / 8

เฉลย Lab 10

เฉลย 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

teryl
Download Presentation

เฉลย Lab 10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. เฉลย Lab 10 Loop

  2. จงเขียนโปรแกรมเพื่อหาค่า 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

  3. TextBoxชื่อ txtInput PictureBoxชื่อ picOutput CommandButtonชื่อ cmdCompute CommandButtonชื่อ cmdEnd

  4. 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 ประกาศตัวแปร

  5. 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

  6. 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

  7. 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

  8. 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

More Related