VB计算s=3 6 9 ... 300
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/11 04:53:14
PrivateSubCommand1_Click()DimsumAsDoubleDimiAsLongDimnAsDoublen=((1/(10^-5))+1)/2'正好等于10^-5时候n的值
数学计算可以简化过程:因为1-2=-1,3-4=-1...所以得出-1+(-1)+...,重复(100/2)次,即代码为(这是最简单而且最快速的办法):DimsAsInteger=-(100/2)如果
DimsAsIntegerDimxAsIntegerDimyAsIntegers=0x=1y=1While(x\y>10^-5)s=s+x\yx=x+1y=y+2Wend---------------
PrivateSubCommand1_click()DimnAsIntegern=100Printf(n)EndSubFunctionf(n)Fori=1Tonf=f+1/iNextiEndFunct
dims,a,is=1a=1i=0DoWhilea
PrivateSubForm_Activate()a5EndSubSuba(nAsLong)DimiAsLongFori=1TonSum=Sum+1/f(i)NextiPrintSumEndSubFu
OptionExplicitPrivateSubCommand1_Click()DimsAsSingle,nAsLong,stAsStringn=1s=0DoDoEventss=s+nst=st&nI
看了上面几位的代码:应该都写错了楼主的问题是:s等于1到N之间每个整数的阶乘相加,而不是N的阶乘我没理解错吧?稍等完毕:在模块中输入代码:PublicFunctionfac(nAsInteger)As
一次都运行不起来,编译错误.next后面的变量必须和循环计数器相同也就是next或nexti都可以,nexts不行如果是nexti那么第一次,i=1,s=1步长为3,所以第一次执行到nexti,i=i
PrivateSubCommand1_Click()DimiAsDoubleDimnAsDoubleDimsumAsDoublesum=0IfNotIsNumeric(Text1.Text)Then'
PublicFunctions(n)Dimi,j,t,resFori=1Tont=1Forj=1Toit=t*jNextres=res+tNexts=resEndFunction
不好意思我好久没用vb了大概如下dimcassingledimxassinglex=inputbox("输入x")c=5*(x-32)/9printc\我以前把vb删了不能试你试试吧
你好!PrivateSubForm_Click()DimiAsIntegerDimsAsIntegerFori=1To100s=s+iNextiPrintsEndSu
PrivateSubCommand1_Click()DimiAsLong,Si=0:S=0WhileSi=i+1S=S+i*(i+1)WendText1.Text=SText2.Text=iEndSu
PrivateSubCommand2_Click()DimIAsLong,SAsLongForI=1To100IfIMod2=0ThenS=S-IElseS=S+IEndIfNextPrintSEnd
PrivateSubCommand1_Click()Dimi,n,sAsIntegern=Val(Text1.Text)s=0Fori=nTo0Step-1s=s+i*(i+1)/2NextiText
PrivateSubCommand1_Click()Dimi,j,tDimsumsum=1Fori=2To10t=1Forj=1Toit=t*2Nextjsum=sum+tNextiPrintsumE
mid从指定位置截取指定长度的容.mid(string,start,len)
PrivateSubCommand1_Click()dimiasintegerfori=1to55step2m=m+inextiprintmendsu
用Sub过程实现:PrivateSubCommand1_Click()DimtAsLongs=0fac01,ts=s+tfac02,ts=s+tfac03,ts=s+tPrint"s=1!+2!+3!