snrg.net
当前位置:首页 >> VB程序,递归法求1+1/2+1/3+1/4+……+1/[F(x%1)+F(x%2)] >>

VB程序,递归法求1+1/2+1/3+1/4+……+1/[F(x%1)+F(x%2)]

知道了,但由于f你定义为long,所以输出整数,与你计算不符,要输出正确结果,要定义为double代码(x可取任何值)Public Function f(x) As LongIf x = 1 Then f = 1 ElseIf x = 2 Then f = 1.5ElseSum = 1.5For i = 3 To xSum = Sum + 1 / (2 * i - 3) 'i-1+i-2Nextf = SumEnd IfEnd FunctionPrivate Sub Form_Click()Label1.Caption = f(Val(Text1.Text))End Sub

Private Sub Command1_Click() Print "第3题:"; Dim n As Integer, s As Double n = InputBox("n=", , 50) For i = 1 To n s = s + 1 / i Next i Print "Sum(" & n & ")="; Format(s, "0.00") End Sub Private Sub Command2_Click() Print "第4

Private Sub Command1_Click()Dim sum, jc, njc = 1n = Val(InputBox("n = "))For i = 1 To njc = jc * isum = sum + 1 / jcNext iMsgBox sum End Sub

function sum1(byval n as intger) as double dim i as integer sum1=0 for i =1 to n sum1=sum1+ 1/i next i end function

0分?给你答一个,加分再来给你答1 dim a(49) dim sum=0 dim j=1 for i=0 to 49 a(i)=1/j j=j*(i+2) sum=sum+a(i) next msgbox sum

这是楼主要的函数过程(先在窗体上添加一个命令按钮) Private Sub Command1_Click() Dim n As Integer n = 100 f n End Sub Function f(n As Integer) As Single Dim i As Integer For i = 1 To n f = f + 1 / i Next i Print "1+1/2+1/3+…+1/100结果为:" & f End Function

Dim sum As Double, n% For n= 1 To Val(Text1) sum = sum + 1 / n Next Text2 = sum

#include void main() { int i,j; int s=0; for(i=1;i { for(j=1;j { s+=j; } } printf("1+(1+2)+(1+2+3)+(1+2+3+4)+……的前20项和=%d",s); }

#include "stdio.h"double sum(double n){ if(n>1) return sum(n-1)+1/n; else return 1;}int main(){ printf("%lf",sum(100));}

高精度,还是保留多少位小数?

相关文档
lpfk.net | zxqk.net | skcj.net | mqpf.net | bnds.net | 网站首页 | 网站地图
All rights reserved Powered by www.snrg.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com