在vb程序中,计算1+1/2+1/3+……+1/n的程序

在vb程序中,计算1+1/2+1/3+……+1/n的程序

VB.NET代码:
dim i,n as Long
dim s as Double
n=Console.ReadLine()
s=0.0
for i=n to 1 step -1
s=s+1.0/i
next i
Console.WriteLine("s={0:e}",s)
Console.WriteLine("s={0:g}",s)

温馨提示:内容为网友见解,仅供参考
无其他回答

在vb程序中,计算1+1\/2+1\/3+……+1\/n的程序
VB.NET代码:dim i,n as Longdim s as Doublen=Console.ReadLine()s=0.0for i=n to 1 step -1s=s+1.0\/inext iConsole.WriteLine("s={0:e}",s)Console.WriteLine("s={0:g}",s)

VB编程求sum=1+1\/2+1\/3+...+1\/n
Private Sub Form_Click()Dim i As Integer Dim sum As Double Dim t As Double sum = 0 i = 1 t = 1 \/ i Do While t > 0.0001 sum = sum + t i = i + 1 t = 1 \/ i Loop Debug.Print "i="; i; "sum="; sum End Sub ...

怎样写VB循环语句代码:1+1\/2+1\/3+1\/4+1\/n=?
x=inputbox("请输入N的值:","数据输入!",1)y=1 for n=1 to x y=y+1\/n next n text1=y

VB编程计算S=1+1\/2+1\/3+1\/4+...+1\/n 要求最后一项不小于0.0001
Private Sub Command1_Click()Dim s As Single n = Val(InputBox("输入 一个整数"))If 1 \/ n < 0.0001 Then MsgBox "1\/n要不小于0.0001"Exit Sub End If For i = 1 To n s = s + 1 \/ i Next Print s End Sub

VB编程 已知N=30,求级数sum=1+1\/2+1\/3+1\/4···+1\/n的和
依据你的描述计算结果如图 代码如下 Private Sub Command1_Click()Sum = 0 For n = 1 To 30 If 1 \/ n <= 0.0000001 Then Exit For Sum = Sum + 1 \/ n Next n Print "计算到第" & n - 1 & "项"Print "和值为:" & Sum End Sub ...

...用两种不同的方法求1+1\/1!+1\/2!+1\/3!+…+1\/n!
s = 1 For i = 1 To 50 s = s + 1 \/ fc(i)Next Print s, i End Sub Private Sub Command2_Click()Dim s, i, k s = 1 Do i = i + 1 k = 1 \/ fc(i)If k < 10 ^ (-6) Then Exit Do s = s + k Loop Print s, i - 1 End Sub Function fc(n)Dim i fc...

VB程序设计教程题,设s=1+1\/2+1\/3……+1\/n,求与8最接近的s的值及与...
Private Sub Form_Click()Dim I As Integer Dim S As Single Form1.Cls S = 0 While S < 8 I = I + 1 S = S + (1 \/ I)Wend Print I; S; Abs(8 - S)I = I - 1 S = S - (1 \/ I)Print I; S; Abs(8 - S)End Sub 根据上面的代码,相信你能很快看出结果。

用VB编写函数过程,计算s=1+1\/2+1\/3+…+1\/100。运行程序时,单击窗体...
private sub Form_Click()dim i as long dim s as currency s=1 for i=2 to 100 s=s+(1\/i)next i msgbox s end sub '这个程序会弹出精确到4位小数的结果,如果需要更高精度的,可以试着把currency换成double。

VB编程题:1+1\/2+1\/3+...+1\/100=?用函数调用的方法
Option Explicit Private Sub Command1_Click()Print MyJ(100)End Sub Private Function MyJ(ByVal J As Integer) As Double Dim i As Integer Dim JJ As Double JJ = 0 For i = 1 To J JJ = JJ + 1 \/ i Next i MyJ = JJ End Function ...

vb编程题求1+2分之一+3分之一……+10分之一
如图所示,望采纳。。。

相似回答