VB求出0~100之内的所有偶数的平方和,将结果显示在窗口界面上
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/24 20:41:55
Fori=0To100IfiMod2=0Thenn=i^2sum=sum+nEndIfNEXT放在IF内就是只对偶数做平方的和,否则不做和.
OptionExplicitOptionBase1PrivateSubForm_Click()Dimi%,j%,k%,n%Dima()AsIntegern=0Fori=1To1000k=0Forj=1
Dima(80)AsInteger,sumAsIntegerDimi!,j!,k!DimtAsBooleanRandomizeFori=0To79a(i)=Int(89*Rnd+10)t=1Forj=
指针赋值写错了指针初始化inta=3;int*p=&a;赋值:inta=3;int*p;p=&a;运行一下这段代码#includevoidmain(){inti,t,a[101],*b;t=0;for
DimiAsLongDimjAsLongDimkAsLongFori=0To100IfiMod2=0Thenj=j+iElsek=k+iNextMsgBox"偶数和:"&j&vbCrLf&"奇数和:"
PrivateSubCommand1_Click()Fori=100To999IfLeft(i,1)=Right(i,1)ThenPrintiNextEndSu
PrivateSubCommand1_Click()Fori=100To999IfLeft(i,1)=Right(i,1)ThenPrinti;n=n+1IfnMod10=0ThenPrintEndI
被5整除的数有一个特点,分为两类,一类是可以被10整除,如10,20……,另一类就是不能被10整除但是能被5整除,如5,15……dimcount1aslong‘先看n整除以10等于多少,比如n是10的
dimiaslong,jaslong,kaslongfori=1to1000forj=ito1000fork=jto1000ifi*i+j*j=k*kthenprinti,":",j,":",knex
PrivateSubCommand1_Click()Dimoushu%,danshu%,sum%oushu=0danshu=0Fori=1To10Randomizesum=Int(Rnd*100)If
PrivateSubCommand1_Click()Fori=2000To9999IfTrim(Str(i))=Trim(StrReverse(Str(i)))ThenPrintStr(i)EndIf
1vari,c11,c7:integer;beginc11:=0;c7:=0;fori:=1to100doifimod11=0theninc(c11)elseifimod7=0theninc(c7);
sum=0fori=1to100if(imod3)thensum=sum+inextiprintsum
PrivateSubCommand1_Click()Fori=100To999IfIsPrime(i)Thenn=n+1Printi;IfnMod10=0ThenPrintEndIfNextiEndS
Dima(5)AsDoublefori=1to5a(i)=fix(rnd*10)nextiFori=1To4Forj=1To5-iIfa(j)temp=a(j)a(j)=a(j+1)a(j+1)=te
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN&q
lz意思是将结果传给a数据和整数个数传给n吧?就是if语句哪里少个括号啦if((i%7==0||i%11==0)&&i%77!=0){a[j++]=i;*n=j;}这样应该可以了吧
Fori=1To100If(Mod(i,7)=0OrMOd(i,11)=0)ANDi77?iendifEndFor**100以内能被7和11同时整队的只有77,如果不用这个,可以用(Mod(i,7)=
楼上算法有问题,多了几个PrivateFunctionprime(nAsInteger)AsBoolean'返回值=True是素数,False不是素数DimkAsIntegerprime=TrueFo
PrivateSubCommand1_Click()Sum=0Fori=0To9Print10*i+7;Sum=Sum+10*i+7NextiPrintPrint"Sum=";SumEndSu