资源预览内容
第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
第9页 / 共10页
第10页 / 共10页
亲,该文档总共10页全部预览完了,如果喜欢就下载吧!
资源描述
光华园学习网更多资料请戳:http:/ghy.swufe.edu.cn/study09/1编写程序,求2的n次幂,n的值通过键盘输入。(要求用循环做,非循环不给分。)Private Sub Command1_Click()Dim i As Long, n As Integer, s As Long n = Int(Val(InputBox(请输入n的值 + 输入框) s = 1 For i = 1 To n s = s * 2 Next i Print s End Sub2从键盘上输入两个正整数A和B,求最大公约数。Private Sub Command1_Click()Dim a As Integer, b As Integer, n As Integer, i As Integer a = Text1.Text b = Text2.Text If a b Then i = a: a = b: b = i Do While b 0 n = a Mod b: a = b: b = n Loop Text3.Text = n End Sub3编写程序,随机生成100个两位整数,并统计出其中小于等于40、大于40小于等于70及大于70的数据个数。Private Sub Form_Click()Dim n As IntegerDim cont1 As Integer, cont2 As Integer, cont3 As Integer n = Int(Rnd * 90 + 10) Print n cont1 = 0 cont2 = 0 cont3 = 0 If n 40 And n 70 Then cont3 = cont3 + 1 End If Print cont1: cont2: cont3 4编写程序,单击窗体时在窗体上输出如下所示的图形。 * * * * * * * * *Private Sub Form_Click()Dim i As Integer, begin As Integerbegin = 5 For i = 1 To 5 Print Tab(begin); For j = 1 To 2 * i - 1 Print *; Next j Print begin = begin - 1 Next i begin = 2 For i = 1 To 4 Print Tab(begin); For j = 1 To 9 - 2 * i Print *; Next j Print begin = begin + 1 Next iEnd Sub5编写程序,计算并输出下面级数前n项(n=80)的部分和。 1-1/2+1/3-1/4+1/5+1/n(n由键盘输入 ,要求用循环做,非循环不给分。)Private Sub Command1_Click() Dim n As Integer, i As Integer Dim sum As Double n = Val(InputBox() sum = 0 For i = 1 To n If i Mod 2 0 Then sum = sum + (1 / i) Else sum = sum - (1 / i) End If Next i Print sumEnd Sub6有100匹马,驮100担货:大马驮3担,中马驮2担,两匹小马驮1担,问有大、中小马各多少?Option ExplicitPrivate Sub Form_Click() Dim x As Integer, y As Integer, z As IntegerPrint 大马, 中马, 小马 For x = 0 To 33 For y = 0 To 50 z = 100 - x - y If (x * 3 + y * 2 + z * 0.5) = 100 Then Print x, y, z End If Next y Next x Print Print 共7种方案。End Sub7编写程序,要求从键盘输入0-6中的一任一个,可对应得到星期日、星期一-星期六。Private Sub Form_Click() Dim n As Integer n = Int(Val(InputBox() Select Case n Case 0 Print n; :星期日 Case 1 Print n; :星期一 Case 2 Print n; :星期二 Case 3 Print n; :星期三 Case 4 Print n; :星期四 Case 5 Print n; :星期五 Case 6 Print n; :星期六 Case Else Print n; :错误 End SelectEnd Sub8编写程序,输出下列三角形: (要求用循环做,非循环不给分。) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1Option ExplicitPrivate Sub Command1_Click() Dim i As Integer, j As Integer, begin As Integer begin = 7 For i = 1 To 4 Print Tab(begin); For j = 1 To 2 * i - 1 Print 1 ; Next j Print begin = begin - 2 Next iEnd Sub9求公式:e=1/1!+1/2!+1/3!+1/n! 直到最后一项小于10(-6)时e的值。(注:程序代码写在命令按钮Command1的Click事件中。)Private Sub Command1_Click() Dim e As Double, nj As DoubleDim n As Long, i As Long e = 0 n = 1 Do nj = 1 For i = 1 To n nj = nj * i Next i e = e + 1 / nj n = n + 1 Loop Until (1 / nj) 0.000001 Print eEnd Sub10编写程序,输出下列三角形: 总行数通过键盘输入。(要求用循环做,非循环不给分。) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1Private Sub Command1_Click() Dim i As Integer, j As Integer, n As Integer, begin As Integer n = Int(Val(InputBox() begin = 1 For i = 1 To n Print Tab(begin); For j = 1 To 9 - 2 * i Print 1 ; Next j Print begin = begin + 2 Next iEnd Sub11输入一串数字,求其中偶数位数字之和。例如输入234567,则求357。Private Sub Command1_Click() Dim str As String, s As String * 1, i As Long, sum As Long str = InputBox() Print str sum = 0 For i = 2 To Len(str) Step 2 s = Mid(str, i, 1) sum = sum + Val(s) Print s Next i Print +=; sumEnd Sub12编写程序,单击窗体时在窗体上输出如下所示的图形。 * * * * * * * * *Private Sub Command1_Click(
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号