循环结构程序代码.docVIP

  • 13
  • 0
  • 约2.47千字
  • 约 5页
  • 2016-11-27 发布于河南
  • 举报
循环结构程序代码

求1+2+3+……100的值。 方法一 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 n = 1 Do While n = 100 s = s + n n = n + 1 Loop Text1.Text = s Text1.Locked = True End Sub 方法二 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 n = 1 Do Until n100 s = s + n n = n + 1 Loop Text1.Text = s Text1.Locked = True End Sub 方法三 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 n = 1 Do s = s + n n = n + 1 If n100 then Exit do Loop Text1.Text = s Text1.Locked = True End Sub 方法四 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 n = 1 Do s = s + n n = n + 1 Loop While n = 100 Text1.Text = s Text1.Locked = True End Sub 方法五 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 n = 1 Do Until n100 s = s + n n = n + 1 Loop Text1.Text = s Text1.Locked = True End Sub 方法六 Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0 For n = 1 To 100 s = s + n Next Text1.Text = s Text1.Locked = True End Sub 设有一张厚为xmm,面积足够大的纸,将它不断对折。试问对折多少次后,其厚度可达珠穆朗玛峰的高度(8848m)。 Private Sub Command1_Click() n = 0 h = Text1.Text Do While h 8848000 n = n + 1 h = 2 * h Loop Text2.Text = n Text2.Locked = True End Sub 设s=1*2*3*4*……*n,求s不大于400000时最大的n。 Private Sub Command1_Click() Dim n As Integer, s As Long CurrentY = Label1.Height + 200 n = 1 s = 1 Do While s = 400000 n = n + 1 s = s * n Print n, s Loop Label2.Caption = n= Str(n - 1) End Sub 将华氏温度转换为摄氏温度。(ss=5/9*(hs—32)) Private Sub Form_Load() Dim hs As String, ss As Single, ts As String Form1.Visible = False ts = 输入华氏温度 Do hs = InputBox(ts, 输入华氏温度, 华氏温度) If hs Then ss = Int((hs - 32) * 5 / 9) MsgBox Str(ss), , 摄氏温度 End If Loop While hs End Sub 用“辗转相除法”求两个正整数的最大公约数。(提示算法:以大数m做被除数,小数n做除数,想出后余数为r;若r0,则m←n,n←r,重复此法直至r=0。最后的n就是最大公约数。) Private Sub Command1_Click() Dim m As Integer, n As Integer m = Val(Text1.Text) n = Val(Text2.Text) If n = 0 Or m = 0 Then MsgBox 数据出错! Unload Me End If If m n Then t = m m = n n = t End If Do r = m Mod n m = n n = r Loop While r 0 Text3.Text = m End S

文档评论(0)

1亿VIP精品文档

相关文档