资源预览内容
第1页 / 共32页
第2页 / 共32页
第3页 / 共32页
第4页 / 共32页
第5页 / 共32页
第6页 / 共32页
第7页 / 共32页
第8页 / 共32页
第9页 / 共32页
第10页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1 实验三实验三 第第 1 题题 四则运算题四则运算题 设计如下窗体,为五个命令按钮编写 5 段代码完成四则运算及退出程序,其中在计算除法时, 如果第二个数是零,在消息框中显示信息“除数为零” 。 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a + b End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a - b End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a * b End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text 2 If b = 0 Then MessageBox.Show(除数为零) Else TextBox3.Text = a / b End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click End End Sub End Class 第第 2 题题 一元二次方程求解一元二次方程求解 输入系数后,单击“求解”按钮后,根据判别式的 3 种不同情况,分别显示如下的不同结果。 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c, delta As Double a = TextBox1.Text b = TextBox2.Text c = TextBox3.Text delta = b * b - 4 * a * c If delta 0 Then Label5.Visible = True Label6.Visible = True Label4.Text = 方程有两个不相等实根 Label5.Text = X1= ; Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(10), k As Integer For i = 1 To 10 a(i) = InputBox(请输入整数) TextBox1.Text += a(i).ToString + Next k = 0 TextBox1.Text += vbCrLf + 交换后: For i = 1 To 10 If i 5 Then k = a(i) a(i) = a(11 - i) a(11 - i) = k TextBox1.Text += a(11 - i).ToString + Else k = a(11 - i) a(11 - i) = a(i) a(i) = k TextBox1.Text += a(i).ToString + End If Next TextBox1.Text = 交换前: + TextBox1.Text End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class 10 第第 2 题题 元素平均元素平均 编写程序,通过使用 inputbox 将 10 个整数放入一个一维数组中,然后计算这 10 个整数的平均 值,在文本框中显示平均值和这 10 个数中低于平均值的数 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(10), sum, i As Integer Dim av As Single For i = 1 To 10 a(i) = InputBox(请输入整数) sum += a(i) Next av = sum / 10 For i = 1 To 10 If a(i) av Then TextBox1.Text += a(i).ToString + End If Next TextBox1.Text = 该组数的平均值为: + av.ToString + vbCrLf + 小于平均值的数有: + TextBox1.Text End Sub End Class 第第 3 题题 矩阵转置矩阵转置 编写程序,实现矩阵转置,即矩阵的行、列互换,将一个 3 行 4 列的矩阵转换为 4 行 3 列,要 示在文本框中分别显示转换前后的两个矩阵。 提示: str = 交换前: + vbCrLf For i = 0 To 3 For j = 0 To 2 str += a(i, j).ToString() + b(j, i) = a(i, j) Next str += vbCrLf Next str += 交换后: + vbCrLf For i = 0 To 2 For j = 0 To 3 str += b(i, j).ToString + Next str += vbCrLf Next 完整程序完整程序: 11 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(,) As Integer = 1, 2, 3, 4, 4, 5, 6, 7, 6, 7, 8, 9 Dim i, j, b(3, 2) As Integer, str As String str = 交换前: + vbCrLf For i = 0 To 2 For j = 0 To 3 str += a(i, j).ToString() + b(j, i) = a(i, j) Next str += vbCrLf Next str += 交换后: + vbCrLf For i = 0 To 3 For j = 0 To 2 str += b(i, j).ToString() + Next str += vbCrLf Next TextBox1.Text = str End Sub End Class 试验七试验七: 第第 1 题题 完全数完全数 编写程序, 找出 22000 之间的所有完全数。 完全数是指某个整数的每个因子之和正好等于 该数本身,例如: 因为 6=1+2+3,28=1+2+4+7+14,所以这两个数都是完全数。 要求: (1)程序窗口界面及控件自行设计。 (2)单击“开始”按钮后,在文本框中显示求出的结果。 (3) 请用进度条提示. Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c, d, i As Integer For a = 2 To 2000 c = 0 For b = 1 To a - 1 d = a Mod b If d = 0 Then c += b End If Next If a = c Then TextBox1.Text += a.ToString + End If ProgressBar1.Value = a 12 Next End Sub End Class 第第 2 题题 杨辉三角形杨辉三角形 打印以下的杨辉三角形(打印 10 行) 。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 提示: (1)使用一个二维数组 a 保存这些数据 (2)第 0 列、主对角线上元素都为 1 (3)其它元素为其上一行元素与上一行左侧元素之和, 即: a(I,j)=a(i-1,j)+a(i-1,j-1) Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles But
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号