晓英振辉奇葩计算机.docx_第1页
晓英振辉奇葩计算机.docx_第2页
晓英振辉奇葩计算机.docx_第3页
晓英振辉奇葩计算机.docx_第4页
晓英振辉奇葩计算机.docx_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

(红色加粗是检索词,绿色是备注)Public Class Form1 Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click Dim var1 As Integer, var2 As String var1 = 12345 var2 = InputBox(输入Var2=, 输入对话框) MsgBox(var2 & Chr(13) + Chr(10) & var1= & Str(var1) MsgBox(var2 & vbCrLf & var1= & Str(var1) End SubEnd Class定义不同变量Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Short 短型 Dim b As Single 单精度 Dim c As Integer 整型 Dim d As Date Dim e1 As String Dim f As Boolean 判断 Dim g As String Dim h As Double 双精度 Dim i As Single Dim j(4, 3) As Integer a = 3.25 b = 546.2 c = 5383149 d = #12/31/2003# e1 = ABCDEF f = False g = 123456 h = 3.24E+100 i = 1.2563E+15 j(0, 0) = 456 MsgBox(a & vbCrLf & b & vbCrLf & c & vbCrLf & d & vbCrLf & e1 & vbCrLf & f & vbCrLf & g & vbCrLf & h & vbCrLf & i & vbCrLf & j(0, 0) End Sub分析不同表达式,定义并输出结果 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim x21, x22, x23, x24 As Single Dim x25, x27, x28 As Boolean Dim x26 As String x21 = Sqrt(3 2 / (2 * 4) 开方 x22 = +Abs(0.123 - 3) 绝对值 x23 = -Sin(30) x24 = Exp(6) + Log(2.135) e的6次方 x25 = 89 & 12 8912 x26 = AB + Str(32.56) + CD x27 = Mid(student, 5) = ent And (5 2) 右边数三位 x27 = Microsoft.VisualBasic.Right(student, 3) = ent And (5 2) x28 = Not (6 2) Or (7 b Then x = a y = b Else x = b y = a End If If c a Then x = c Else If c b Then y = c End If End If MsgBox(最大数 & x & 最小数 & y) End SubIf 语句进行有条件的计算 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim t As Single, f As Single t = InputBox(请输入t) If t = 90 Then y = A ElseIf x = 80 Then y = B ElseIf x = 70 Then y = C ElseIf x = 60 Then y = D Else y = E End If MsgBox(成绩 & x & 等级为 & y) End SubSelect语句进行有条件的计算 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim x As Single, y As Single x = InputBox(请输入x) Select Case x Case Is = -1 y = x - 1 Case Is = 2 y = 2 * x Case Is = 0 Then x1 = -b + Math.Sqrt(x) / 2 / a x2 = -b - Math.Sqrt(x) / 2 / a MsgBox(x1= & Format(x1, #.#) & x2= & Format(x2, #.#) Else x1 = Math.Sqrt(-x) / 2 / a x2 = -Math.Sqrt(-x) / 2 / a MsgBox(x1= & -b / 2 / a & x1 & i x2= & -b / 2 / a & x2 & i) End If End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim x As Single, y As Single x = InputBox(请输入x) If x = -1 Then y = x - 1 ElseIf x = 2 Then y = 2 * x ElseIf x = 10 Then y = x * (x + 2) End If MsgBox(y= & y) End SubEnd Class1. 计算1/(1*2)+1/(2*3)+.+1/(n*n+1)Public Class Form1 Dim a(19) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim n As Integer Dim s As Single s = 0 n = InputBox(请输入n) For i = 1 To n s = s + 1 / (i * (i + 1) Next MsgBox(s= & s) End Sub2. 10个元素的数据,计算下标为奇数的元素和为偶数的元素和 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim a(10) As Integer Dim i As Integer Dim x As Integer Dim y As Integer x = 0 y = 0 For i = 1 To 10 InputBox(请输入第 & i & 个数) If i Mod 2 = 0 Then x = x + a(i) Else y = y + a(i) End If Next MsgBox(下标为奇数的元素和为 & y & 下标为偶数的元素和为 & x) End Sub3. 正三角* Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim r As Integer, s As Integer, c As Integer, y(5) As String, j As Integer, ys As String ys = r = 1 Do While r = 4 c = 10 - r : s = 1 y(r) = y(r) & Space(c + s) Do While s = 1 c = 10 - r : s = 1 ys = ys & Space(c + s) Do While s 50 Then x = x + 1 ElseIf a(i) 10 Then y = y + 1 End If Next MsgBox(s & vbCrLf & 50万元以上的业务人数为 & x & ,10万元以下的业务人数为 & y) End Sub6. 20个数据从高到低排序 Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim a(19) As Integer Dim t As Integer Dim i As Integer Dim j As Integer Dim x As String Dim y As String x = y = For i = 0 To 19 a(i) = Int(Rnd() * 100) x = x & a(i) & , Next For i = 0 To 19 For j = 19 To i + 1 Step -1 If a(j) a(j - 1) Then t = a(j) a(j) = a(j - 1) a(j - 1) = t End If Next y = y & a(i) & , Next MsgBox(x & vbCrLf & y) End Sub7. 8位数的整数,0-9这10个数字出现次数 Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Dim a As Integer Dim b(9) As Integer Dim s As Integer Dim u As String Dim i As Integer Randomize() a = Int(Rnd() * 90000000 + 10000000) For i = 0 To 7 s = Mid(a, i + 1, 1) b(s) = b(s) + 1 Next u = 8位数为:( & a & ) & vbCrLf For i = 0 To 9 u = u & i & 出现次数: & b(i) & vbCrLf Next MsgBox(u) End Sub8. 产生20个8位整数 Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Dim b(19) As Integer Dim i As Integer Dim s As String s = For i = 0 To 19 b(i) = Int(Rnd() * 90000000 + 10000000) s = s & b(i) & vbCrLf Next MsgBox(s) End Sub9. Do while 做第1题 ,且当1/(n*n+1)= 0.000001 s = s + t i = i + 1 t = 1 / (i * (i + 1) Loop MsgBox(s= & s) End Sub10. Do until loop Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click Dim i As Integer Dim t As Single Dim s As Single i = 1 t = 1 / (i * (i + 1) s = 0 Do s = s + t i = i + 1 t = 1 / (i * (i + 1) Loop While t = 0.000001 MsgBox(s= & s) End Sub11. 动态数组 Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click Dim a() As Integer Dim i As Integer Dim n As Integer Dim x As Integer Dim y As Integer x = 0 y = 0 n = InputBox(请输入数组的数量) ReDim a(n) For i = 1 To n a(i) = InputBox(请输入第 & i & 个数) If i Mod 2 = 0 Then x = x + a(i) Else y = y + a(i) End If Next MsgBox(下标为奇数的元素和为 & y & 下标为偶数的元素和为 & x) End Sub12. 输入字符串,递减排序 Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click Dim s As String Dim y As String Dim t As String Dim a() As String Dim i As Integer Dim j As Integer Dim l As Integer t = y = s = InputBox(请输入要排序的字符串) l = Len(s) ReDim a(l) For i = 1 To l a(i) = Mid(s, i,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论