s=0,for i=1 to 5,for j=1 to i,for k=j to 4,s=s+1,next k,next j,next i,msgbox s,求详解s= 0For i = 1 To 5For j = 1 To iFor k = j To 4 s = s + 1Next k Next j Next iMsgBox sA.4 B.5 C.38 D.40自己算的和四个选项都不一样.

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 14:39:32
s=0,fori=1to5,forj=1toi,fork=jto4,s=s+1,nextk,nextj,nexti,msgboxs,求详解s=0Fori=1To5Forj=1ToiFork=jTo4s

s=0,for i=1 to 5,for j=1 to i,for k=j to 4,s=s+1,next k,next j,next i,msgbox s,求详解s= 0For i = 1 To 5For j = 1 To iFor k = j To 4 s = s + 1Next k Next j Next iMsgBox sA.4 B.5 C.38 D.40自己算的和四个选项都不一样.
s=0,for i=1 to 5,for j=1 to i,for k=j to 4,s=s+1,next k,next j,next i,msgbox s,求详解
s= 0
For i = 1 To 5
For j = 1 To i
For k = j To 4
s = s + 1
Next k
Next j
Next i
MsgBox s
A.4 B.5 C.38 D.40
自己算的和四个选项都不一样.

s=0,for i=1 to 5,for j=1 to i,for k=j to 4,s=s+1,next k,next j,next i,msgbox s,求详解s= 0For i = 1 To 5For j = 1 To iFor k = j To 4 s = s + 1Next k Next j Next iMsgBox sA.4 B.5 C.38 D.40自己算的和四个选项都不一样.
实际就是看s一共运行了多少次.这个并不难的.一共三层for语句,算出第三层for语句运行多少次就行了.
i=1时,j=1时s运行4次;
i=2,j=1,s运行4次;j=2,s运行3次;
i=3,j=1,s运行4;j=2,s运行3;j=3,s运行2
i=4,j=1,s运行4;j=2,s运行3;j=3,s运行2;j=4,s运行1
i=5,j=1,s运行4;j=2,s运行3;j=3,s运行2;j=4,s运行1;j=5,s运行0
4*5+3*4+2*3+1*2=20+12+6+2=40
所以选择D