用VB语言编程计算1-10之间奇数的平方和

如题所述

话说楼上的已经很好了,还要在做什么?
算了,给你个实例吧,添加一个command按钮,输入以下代码
Option Explicit

Private Sub Command1_Click()
Dim result As Long
Dim i As Integer
For i = 1 To 9 Step 2
result = result + i ^ 2
Print result
End Sub
这样窗体上就会显示出1-10之间奇数的平方和

不会再追
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-01-02
for i= 1 to 9 step 2
a=a+i^2
next
print a
不会再追追问

可以写的更规范完整些么?

用VB语言编程计算1-10之间奇数的平方和
Private Sub Command1_Click()Dim result As Long Dim i As Integer For i = 1 To 9 Step 2 result = result + i ^ 2 Print result End Sub 这样窗体上就会显示出1-10之间奇数的平方和 不会再追

用VB的循环语句求1到100的奇数和与偶数积
Private Sub Form_Click()Dim i As Integer, sum As Integer, aa As Double aa = 1 For i = 1 To 100 If i Mod 2 = 0 Then aa = aa * i Else sum = sum + i End If Next i Debug.Print aa, sum End Sub

vb中怎样实现计算1—n的奇偶数之和:(n为自然数)
jishuhe=jishuhe+i'如果是奇数,就将其累加到技术和变量中 end if next msgbox "偶数和为" & oushuhe“,奇数和为"& jishuhe'利用msgbox显示结果 end sub

VB怎么编写【m,n】之间奇数平方和语句
if i mod 2=1 then s=s+i*i end if next i print “m到n区间的平方和是:”,s m和n的取值自己在for i=m to n这里改。

用VB写出1-100的所有奇数和偶数和
Private Sub Command1_Click()Dim i, sum1, sum2 As Integer sum1 = 0 sum2 = 0 For i = 1 To 100 If i Mod 2 = 1 Then sum1 = sum1 + i Else sum2 = sum2 + i End If Next i Print "奇数和为" & sum1 Print "偶数和为" & sum2 End Sub ...

vb 编程 求用inputbox函数输入的10个数的和数和连乘积
应该是这样的 Private Sub Form_DblClick()Dim g As Single Dim i As Integer Dim j As Double g = 0 j = 1 For i = 1 To 10 k = InputBox("Input your number", "Inout")g = g + k j = j * k Next i Print "和=" & g Print "连乘积=" & j End Sub ...

VB编程“求1到1000以内所有奇数之和”(do while 结构)
Private Sub Command1_Click()Dim i As IntegerDim s As Integers = 0: i = 0Do While i <= 1000i = i + 1:If i Mod 2 = 1 Then s = s + iEnd IfLoopPrint "计算1至1000之间的奇数之和为:"; sEnd Sub没有学过VB但是楼主的程序确实存在问题,这样改一下应该差不多了,对于楼上说的溢出...

vb随机输入一个数字,生成这个数以内的奇数,并且计算这些数的和
所以最后一个奇数要小于输入的数Dim sum As IntegerIf n Mod 2 = 0 Then '根据等差数列求和公式 s=(a1+an)*m\/d,这里 a1=1,an=n-1(n为偶数)或an=n-2(n为奇数),项数m=n\/2(n为偶数)或m=(n-1)\/2(m为奇数),公差d=2 sum = n * n \/ 2 \/ 2Else sum = (1 + ...

跪求用VB编程计算1~100的奇数.偶数.整数和??
Dim sumJ As Integer, sumO As Integer, sumZ As Integer, i As Integer Private Sub Form_Load()For i = 1 To 100 sumZ = sumZ + i If i Mod 2 = 0 Then sumO = sumO + i Else sumJ = sumJ + i End If Next Text1.Text = sumZ & vbCrLf & sumJ & vbCrLf & sumO En...

VB中求1到N的奇数和(求救)
msgbox("请输入正确的奇数")end Private Sub form_click()Dim N As Integer Dim Sum As Integer Dim i As Integer N:N = InputBox(" enter N(NΪÈÎÒâÆæÊý)")if N mod 2 =1 then msgbox("请输入正确的奇数")goto ...

相似回答