posts - 70,comments - 80,trackbacks - 0
[ 题目1 ] 本程序用于判断输入的正整数是否为降序数。设正整数 n= d 1 d 2 d 3 …d k 如果满足 d i >= d i+1 (i=1,2,… k-1 , n 就是一个降序数。如 4321 10 433 都是降序数。
答:o_v11.JPG
源程序:
Option Explicit
Private Sub Form_Click()
Dim n As Integer, flg As Boolean
n = InputBox("Input n:")
Call Conver(n, flg)
If flg = True Then
   Print n; "是降序数"
Else
   Print n; "不是降序数"
End If
End Sub

Private Sub Conver(n As Integer, flg As Boolean)
Dim x As String, i As Integer
x = Trim(Str(n))
For i = 1 To Len(x) - 1
   If Mid(x, i, 1) < Mid(x, i + 1, 1) Then Exit For
Next i
If i = Len(x) Then flg = True Else flg = False
End Sub

[题目2]编写程序,根据身高计算标准体重。计算公式如下:

男的标准体重(kg)=身高(cm)-100
女的标准体重(kg)=身高(cm)-105

[编程要求]1.程序参考界面如图所示,单选按纽“男”的Value属性初始值为True,编程时不得增加或减少界面对象或改变对象的种类,但界面元素的大小、位置可随意设置;界面中的中文说明可用表1中对象的英文代替。

2.单击“计算”按纽,根据输入的身高和计算公式计算相应性别的标准体重,并显示在文本框中。

3.单击结束按纽,结束程序运行。

1

中文

英文

身高

Height

体重

Weight

Man

Woman

计算

Calculate

结束

Finish

 

 答:o_v1.JPG
源程序:
Private Sub Command1_Click()
If Text1.Text = "" Then
    MsgBox "请输入身高!", vbOKOnly
    Text1.SetFocus
    Exit Sub
End If
If Option1.Value = True Then Text2.Text = Int(Val(Text1.Text)) - 100
If Option2.Value = True Then Text2.Text = Int(Val(Text1.Text)) - 105
End Sub

Private Sub Command2_Click()
End
End Sub

posted on 2006-10-02 09:33 木子李 阅读(524) 评论(0)  编辑 收藏 引用 网摘 所属分类: Visual Basic 课堂

只有注册用户登录后才能发表评论。