June 8, 2007

計算機程式(期末考)

Function SunToN(n As Long) As String
'計算1+2+3+...+N

Dim s As Long

Dim i As Integer

For i = 1 To n
s = s + i
Next
SunToN = "1+2+3+...+" & n & " = " & s

End Function



Function mySunIF(myR As Range, a As Long) As Double
'單欄範圍的和
Dim s As Long
Dim i As Interior, no As Integer
no = myR.Cells.Count '指定範圍的的資料數

For i = 1 To no
If myR.Cells(i, 1) >= a Then
s = s + myR.Cells(i, 1)
End If
Next
mySunIF = s

End Function




Function myCountINIF(myR As Range, a As Long, b As Long) As Double

Dim s As Long

Dim i As Interior, no As Integer

no = myR.Cells.Count '指定範圍的的資料數

For i = 1 To no

If myR.Cells(i, 1) >= a And myR.Cells(i, 1) <= b Then

s = s + 1

End If

Next

myCountIN = s




End Function


Function Sun2N(n As Long) As String


Dim s As Long

Dim i As Integer, p As Long
p = n Mod 2


If (p = 0) Then

For i = 2 To n Step 2

s = s + i

Next
Sun2N = "2+4+...+" & n & " = " & s

Else
Sun2N = "IN需為偶數"

End If

End Function

Today's Visitors: 0 Total Visitors: 15
Personal Category: 心情 Topic: 未分類
Previous in This Category: 心情   Next in This Category: 忙碌...庸碌...永無止盡的路!?
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0