1、一.选择结构题目:在下面的程序段中过程 pd 可以判断任意三个数能否构成三角形的三边,利用该过程的判定结果, 对能构成三角形的计算其面积,构不成的显示“不能构成三角形“-Option ExplicitPrivate Sub Form_Click()*FOUND*Dim x%, y%, z%, s%, b As Boolean, h As Singlex = InputBox(“请输入三角形的边长“)y = InputBox(“请输入三角形的边长“)z = InputBox(“请输入三角形的边长“)b = pd(x, y, z)h = (x + y + z) / 2*FOUND*If Not b
2、 Thens = Sqr(h * (h - x) * (h - y) * (h - z)Print “三角形面积是“; sElsePrint “不能构成三角形“End IfEnd Sub*FOUND*Public Function pd() As BooleanIf x 0 And y 0 And z 0 And x + y z And x + z y And y + z x Thenpd = TrueElsepd = FalseEnd IfEnd Function(答案 1) Dim x% , y% , z% , s! , b As Boolean , h As Single(答案 2) I
3、f b=true Then(答案 3) Public Function pd(x%, y%, z%) As Boolean-题目:请根据下列描述编写购物优惠程序。某商场为了加速促成商品流通,采用购物打折的优惠办法,每位顾客一次购物(1)在 100 元以上者,按九五折优惠; (2)在 200 元以上者,按九折优惠;(3)在 300 元以上者,按八折优惠;(4)在 500 元以上者, 按七折优惠。-Option ExplicitPrivate Sub Command1_Click()Dim x As Single, y As Singlex = Val(Text1.Text)If x 100 ,i
4、s= 0 And a “#“*FOUND*If t = “a“ And t = “a“ And t 3000Print “从 1 到:“; i; “的和是“; sEnd Sub(答案 1) s =0(答案 2) i = i + 1(答案 3) Loop until s 3000-题目:用自定义函数的方法求 sum(x) ,求当-1x1 时, sum(x)=x/2!+x2/3!+x3/4!+xn/(n+1)!, 当 x1 或 x-1 时,函数值为 0。当 n=0 时,输入数据错误。X、N 都是由用户输入。-Option ExplicitPrivate Sub Command1_Click()Di
5、m s As SingleDim n As Integer, x As Single, k As Integern = Val(InputBox(“Please input a integer value:“)x = Val(InputBox(“Please input a single value:“)If n 1 Or x xPrint k;i = jj = k*FOUND*k = i - jLoopEnd Sub(答案 1) call fb (x)(答案 2) Do While k a(n) Then n = tNext n*FOUND*If t = m Thenw = a(m)a(m)
6、 = a(t)a(t) = wEnd IfNext mFor m = 1 To 7Print a(m)Next mEnd Sub(答案 1) For n = m + 1 To 7(答案 2) If a(t) a(n) Then t = n(答案 3) If t m Then-题目:以下程序用于建立一个三行三列的矩阵,使其两条对角线上数字为 1,其余位置为 0-Option ExplicitPrivate Sub Form_Click()Dim x(3, 3), n As Integer, m As IntegerFor n = 1 To 3For m = 1 To 3*FOUND*If n =
7、 m Then x(n, m) = 1 Else x(n, m) = 0*FOUND*Next n, mFor n = 1 To 3For m = 1 To 3*FOUND*Print x(m, n)Next mPrintNext nEnd Sub(答案 1) If n = m Or m = 3 + 1 - n Then x(n, m) = 1 Else x(n, m) = 0(答案 2) Next m, n(答案 3) Print x(n, m);-题目:下面的程序用来产生并输出图示的杨辉三角。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1-Opti
8、on ExplicitPublic Sub readin(a() As Integer, n As Integer)Dim i, j As IntegerFor i = 1 To n*FOUND*a(i, n) = 1a(i, 1) = 1Next iFor i = 3 To n*FOUND*For j = 2 To na(i, j) = a(i - 1, j) + a(i - 1, j - 1)Next jNext iEnd SubPublic Sub printf(a() As Integer, n As Integer)Dim i, j As IntegerFor i = 1 To n*FOUND*For j = 1 To nPrint Tab(5 * j + 10); a(i, j);Next jPrintNext iPrintEnd Sub