Re: [ASP.NET ] 一個2維陣列的問題..

看板Visual_Basic作者 (無)時間17年前 (2006/11/01 17:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
※ 引述《Firedance (迎火飛舞)》之銘言: : ※ 引述《Firedance (迎火飛舞)》之銘言: : : 標題: Re: [ASP.NET ] 一個2維陣列的問題.. : : 時間: Wed Nov 1 02:40:20 2006 : : 推 commiserate:有錯誤訊息嗎?版本? 11/01 08:51 : 是我宣告變數值宣告錯了, : 我是用Visual Studio 2005(語言用VB)寫的 : 我後來把程式改了一下..如下面網址.. : http://www.chinesefreewebs.com/chiahung/asp/2array1.txt : 先將A(1,1).A(1,2)的值加起來然後讓平均產生在最右邊. : 但我想說如果要讓平均產生在最下面的話 : 就必需要先產生 : A(1,1).A(1,2) : A(2,1).A(2,2) : . : . : . : 的數字,然後在將 A(1,1).A(2,1).A(N.1)的值加起來平均放到下面 : A(1,1). : A(2,1). : A(3,1) : 平均 : 就因為想放到下面我就寫不出來了..我都是在紙上先寫出來然後 : 在去想要怎麼寫,可是這個我先將分數產生出來之後卻不知道如 : 何加程式碼.. : 想說將Total += A(I,J)改成 Total += A(I,1),但好像也不行. : 請問有人知道如何修改的嗎?? : 請問有人知道要怎麼寫的呢? 我就直接改你的程式碼囉 標黃色是我加上去的 標藍色是我沒用到的部分 就是產生成績再畫表格 請享用 Dim Students As Integer = Microsoft.VisualBasic.Interaction.InputBox("請輸入學生人數") Dim Subject As Integer = Microsoft.VisualBasic.Interaction.InputBox("請輸入學習科目數量") Dim A(Students, Subject), I, J As Int16, Total As Int64, Value As String, Ave, Average, Valuer As Single Dim RandomNumber As Random = New Random '自此開始為新增 Dim total_Student(Students) As Double, total_Subject(Subject) As Double For I = 1 To Students For J = 1 To Subject A(I, J) = RandomNumber.Next(0, 101) total_Student(I) += A(I, J) total_Subject(J) += A(I, J) Next Next '自此結束為新增 Response.Write("<title>計算平均分數</title><center><table border='1' cellpadding='2' width='600' cellspacing='2'>") Valuer = 0 For I = 1 To Students Response.Write("<tr>") 'Total = 0 For J = 1 To Subject 'A(I, J) = RandomNumber.Next(0, 101) 'Total += A(I, J) If A(I, J) >= 60 Then Value = "<font color=blue>" & A(I, J) & "</font>" Else Value = "<font color=red>" & A(I, J) & "</font>" End If Response.Write("<td>" & "No" & I & "=" & Value & "</td>") Next 'Ave = Math.Round(Total / Subject, 1) Ave = total_Student(I) / Subject '新增 Valuer += Ave If Ave >= 60 Then Response.Write("<td>平均:<font color='blue'>" & Ave & "</font></td>") Else Response.Write("<td>平均:<font color='red'>" & Ave & "</font></td>") End If Next '自此開始為新增 Response.Write("<tr>") For J = 1 To Subject Ave = total_Subject(J) / Students If Ave >= 60 Then Response.Write("<td>平均:<font color='blue'>" & Ave & "</font></td>") Else Response.Write("<td>平均:<font color='red'>" & Ave & "</font></td>") End If Next '自此結束為新增 Average = Math.Round(Valuer / Students, 1) Response.Write("<td><font color='Green'>總平均:" & Average & "</font></td>") '新增 Response.Write("<font color='Green'>" & "求每位學生平均分數 <br>" & "</font><br>") Response.Write("<tr align='center'><td colspan='" & Subject + 1 & "'><font color='Green'>" & Students & "位學生平均分數為:" & Average & "</font></td></tr>") Response.Write("</table><br><font color='blue'>考試科目數:" & Subject & " 學生人數:" & Students & "</font></center>") -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.63.21.245
文章代碼(AID): #15I6DPqF (Visual_Basic)
文章代碼(AID): #15I6DPqF (Visual_Basic)