2016年6月17日 星期五

TO Z1A

期末仍是以小考2次為主,以下為變化的部份佔分<=20%

先給3個程式,其它的明日再上傳


 ' 程式1: 執行後 X=?、 Y=? 、 Z=? 、 S(3)  、 W=?
        ' 在即時運算視窗顯示: 635,95,79.375,92,12.6
        Dim S() As Integer = {0, 76, 85, 92, 88, 79, 66, 54, 95}
        Dim X As Integer = 0
        Dim Y As Integer = 0
        Dim Z As Double
        Dim n = S.Length - 1
        For A = 1 To n
            X += S(A)
            If S(A) > Y Then Y = S(A)
        Next
        Z = X / n
        Dim W = Math.Round(S(3) - Z, 1)
        Debug.Print(X & "," & Y & "," & Z & "," & S(3) & "," & W)

    ' 程式2: 執行後 A(5,5)、A(2,3)、  A(5,7)內容
        '  在即時運算視窗顯示: 19,20,48
        Dim n As Integer = 8
        Dim N1 As Integer = n - 1
        Dim N2 = n * n
        Dim C = 1
        Dim A(n, n) As Integer
        For i = 0 To N1
            For j = 0 To N1
                Dim i4 = i Mod 4, j4 = j Mod 4
                If i4 = j4 Or i4 + j4 = 3 Then
                    A(i, j) = N2 + 1 - C
                Else
                    A(i, j) = C
                End If
                C += 1
            Next
        Next
        Debug.Print(A(5, 5) & "," & A(2, 3) & "," & A(5, 7))

    ' 程式3: 執行後 P(2)、P(12)、P(22) 內容
        ' 在即時運算視窗顯示: 5,41,83
        Dim d(500) As Boolean
        Dim P(150) As Integer
        d(0) = True : d(1) = True
        Dim n As Integer = 200
        Dim C As Integer = 0
        For i = 2 To n
            If d(i) = False Then
                P(C) = i
                C += 1
                For j = i + i To n Step i
                    d(j) = True
                Next
            End If
        Next
        Debug.Print(P(2) & "," & P(12) & "," & P(22))


0 意見:

張貼留言