VB计算出0~n间偶数的总和
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/19 03:01:32
Fori=0To100IfiMod2=0Thenn=i^2sum=sum+nEndIfNEXT放在IF内就是只对偶数做平方的和,否则不做和.
PrivateSubForm_Click()n=2DoWhiles
DimiasInteger,jasInteger,oasIntegerj=0o=0Fori=1To100Step2j=j+io=o+(i+1)NextDebug.print"100以内的奇数和:"&j
vara:array[1..32767]ofinteger;i,j,s1,s2,n:integer;x:real;beginreadln(n);fori:=1tondoread(a[i]);fori:
1.DimnAsInteger,iAsIntegerDimjiAsDoublen=Val(Text1.Text)i=1ji=1Doji=ji*ii=i+1Ifi>nThenExitDoLoopPrin
PrivateSubCommand1_Click()Dimi,j,kFori=1To10k=1Forj=1Toik=k*jNextPrinti&"!="&kNextEndSub再问:如果用inputb
PrivateSubForm_Click()DimHeAsLongDimIAsInteger,MAsInteger,NAsIntegerM=Int(Val(InputBox("M的值","输入",3)
PrivateSubForm_Click()DimnAsIntegern=InputBox("请输入一个正整数n")s=1Fori=nTo1Step-1s=s*iNextiPrintn&"!="&sE
PrivateSubCommand1_Click()Fori=0ToList1.ListCount-1j=j+1Ifj=11ThenExitForIfList1.List(i)NextEndSubPr
privatesubcommand1_click()dimjs,os,i,afori=1to20a=int(Rnd*99)+1ifamod2=0thenjs=js+ielseos=os+inextpr
给个最简单的示例你x=0:y=0fori=1to10a=inputbox("请输入一个任意整数!","提示")ifa=""thenmsgbox"你至少输入一个数!","提示":i=i-1elseif(
tmp = InputBox("随便输入几个数,用逗号隔开就可以了.") &n
在此创建一个文本框,按钮,标签都是原先默认名不要改PrivateFunctiona(cAsInteger)Ifc>=0AndcMod2=0ThenLabel1.Caption=Text1.Text&"
Functions(ByValaAsInteger,ByValbAsInteger)AsIntegerDimiAsIntegerFori=1To1000IfiModa=0AndiModb=0Thens
Functiona(n)DimmAsLongm=n\2a=m*(m+1)EndFunction
dimnaslong'n是被判断的数ifn\2=0then'n=偶数else'n=奇数endif
ivateSubCommand17_Click()DimiAsLong,kAsLong,jAsLong,oAsLongk=Val(Text1.Text)‘要计算的数j=0o=0Fori=1TokIfi
Sub aa()'用9行数据做说明,看是不是你要的东西;Dim x As IntegerFor x = 2 To
100个自然数,奇数的个数比偶数的个数多那么奇数最少有51个,偶数有49个又根据:偶数+偶数=偶数奇数+奇数=偶数奇数+偶数=奇数得出:51个奇数的和为奇数,再加上49个偶数总和应该是奇数但10000
PrivateSubCommand1_Click()Dimli_iAsIntegerli_i=Val(Text1.Text)Ifli_i