vb循环语句的题目:计算3-1/2+2/3-3/4+…+ N/(N+1)的结果(N=10).(3.26345)我是这么写的:For n = 1 To 10m = n / (n + 1)o = m * (-1) ^ nk = k + oNext nPrint "k="; k + 3但老师说这不够简洁.劳烦诸位给修改啦!
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 04:15:43
vb循环语句的题目:计算3-1/2+2/3-3/4+…+ N/(N+1)的结果(N=10).(3.26345)我是这么写的:For n = 1 To 10m = n / (n + 1)o = m * (-1) ^ nk = k + oNext nPrint "k="; k + 3但老师说这不够简洁.劳烦诸位给修改啦!
vb循环语句的题目:计算3-1/2+2/3-3/4+…+ N/(N+1)的结果(N=10).(3.26345)
我是这么写的:For n = 1 To 10
m = n / (n + 1)
o = m * (-1) ^ n
k = k + o
Next n
Print "k="; k + 3
但老师说这不够简洁.劳烦诸位给修改啦!
最好能附上原因!
还有另一题百钱买百鸡(公鸡5元、母鸡3元、小鸡1/3元,100元刚好买100只)
For a = 1 To 20
For b = 1 To 33
c = 100 - a - b
If (a + b + c = 100) And (a * 5 + b * 3 + c * 1 / 3 = 100) Then Print "a="; a,"b="; b,"c="; c
Next b
Next a
能不能改成用两个变量的?
vb循环语句的题目:计算3-1/2+2/3-3/4+…+ N/(N+1)的结果(N=10).(3.26345)我是这么写的:For n = 1 To 10m = n / (n + 1)o = m * (-1) ^ nk = k + oNext nPrint "k="; k + 3但老师说这不够简洁.劳烦诸位给修改啦!
m = n / (n + 1)
o = m * (-1) ^ n
这两句合成一句o=(-1)^n*n/(n+1)不知道这个地方有没有数值转换?小心
第二道题
Private Sub Form_Activate()
Dim a, b As Integer
For a = 1 To 20
For b = 1 To 33
'c = 100 - a - b ’C变量用100-a-b代替 就用两个变量了
If (a * 5 + b * 3 + (100 - a - b) * 1 / 3 = 100) Then Print "公鸡="; a, "母鸡="; b, "小鸡="; 100 - a - b
Next b
Next a
End Sub