vb中如何用函数求100以内偶数的平方和这是我编写的程序,不知道错在哪里了,求指正.Function Fun()Dim a As IntegerDim b As Integerb = 0For a = 1 To 100If a Mod 2 = 0 Thenb = b + a * aEnd IfNext aFun = b

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 16:32:55
vb中如何用函数求100以内偶数的平方和这是我编写的程序,不知道错在哪里了,求指正.Function Fun()Dim a As IntegerDim b As Integerb = 0For a = 1 To 100If a Mod 2 = 0 Thenb = b + a * aEnd IfNext aFun = b
xRKoQ+wc"kJbRU&30T:@%!)!sg_x]ι}'}-i7!3elt| CH1ac|խyXԜ!]<DO ԛki 1=n/PX#v-iquOX+dwQ,"d7Lp-_×YFxB"/_D)}4D^y:qM3AgZ*vB,<Ț'/Vs

vb中如何用函数求100以内偶数的平方和这是我编写的程序,不知道错在哪里了,求指正.Function Fun()Dim a As IntegerDim b As Integerb = 0For a = 1 To 100If a Mod 2 = 0 Thenb = b + a * aEnd IfNext aFun = b
vb中如何用函数求100以内偶数的平方和
这是我编写的程序,不知道错在哪里了,求指正.
Function Fun()
Dim a As Integer
Dim b As Integer
b = 0
For a = 1 To 100
If a Mod 2 = 0 Then
b = b + a * a
End If
Next a
Fun = b

vb中如何用函数求100以内偶数的平方和这是我编写的程序,不知道错在哪里了,求指正.Function Fun()Dim a As IntegerDim b As Integerb = 0For a = 1 To 100If a Mod 2 = 0 Thenb = b + a * aEnd IfNext aFun = b
Function calc()
dim a as integer
dim b as long
for a = 0 to 100 step 2
b = b + a^2
next a
calc = b
end function
这个算法比你的优化一些,如果你想用自己的代码
就要定义b为长整型,因为你明显猜的出偶数的平方和会很大,会超出Integer的最大范围,造成溢出
还有,也许是你黏贴的时候粗心了,少了函数的结尾End Function
写程序一定要细心