VB编程题,速度,谢谢
1.有函数:y=x(x<1)3x-2(1<=x<10)4x-12(x>=10)编写程序,输入X值后,则输出相应y值。要求用“If...elseif...Endif”和用“...
1.有函数:y=x(x<1) 3x-2(1<=x<10) 4x-12(x>=10)编写程序,输入X值后,则输出相应y值。要求用“If...elseif...Endif”和用“select case”两种方法完成该题目。2。编写程序,输出所有的“水仙花数”。所谓水仙花数是指一个三位数,其各位数字立方和等于该数本身。例如,153是一水仙花数,因为153=1的三次方+5的三次方+3的三次方
展开
2个回答
2013-07-20
展开全部
1、函数:第一种方法:Private Sub Command1_Click()
Dim x, y
x = Text1.Text
If x < 1 Then
y = x
ElseIf x >= 1 And x < 10 Then
y = 3 * x - 2
ElseIf x >= 10 Then
y = 4 * x - 12
End If
Label1.Caption = y
End Sub第二种方法:Private Sub Command2_Click()
Dim x, y
x = Text1.Text
Select Case x
Case Is < 1
y = x
Case Is < 10
y = 3 * x - 2
Case Is >= 10
y = 4 * x - 12
End Select
Label1.Caption = y
End Sub2、水仙花数:Private Sub Command3_Click()
Dim A%, B%, C%, I$, N$
N = ""
For A = 1 To 9
For B = 0 To 9
For C = 0 To 9
If A ^ 3 + B ^ 3 + C ^ 3 = 100 * A + 10 * B + C Then
I = "," & A & B & C
N = N & I
End If
Next
Next
Next
Label1.Caption = "水仙花数有:" & N
End Sub第一题的两种方法各有一个命令按钮,共用一个文本框,第二题也一个命令按钮,两题共用一个标签
Dim x, y
x = Text1.Text
If x < 1 Then
y = x
ElseIf x >= 1 And x < 10 Then
y = 3 * x - 2
ElseIf x >= 10 Then
y = 4 * x - 12
End If
Label1.Caption = y
End Sub第二种方法:Private Sub Command2_Click()
Dim x, y
x = Text1.Text
Select Case x
Case Is < 1
y = x
Case Is < 10
y = 3 * x - 2
Case Is >= 10
y = 4 * x - 12
End Select
Label1.Caption = y
End Sub2、水仙花数:Private Sub Command3_Click()
Dim A%, B%, C%, I$, N$
N = ""
For A = 1 To 9
For B = 0 To 9
For C = 0 To 9
If A ^ 3 + B ^ 3 + C ^ 3 = 100 * A + 10 * B + C Then
I = "," & A & B & C
N = N & I
End If
Next
Next
Next
Label1.Caption = "水仙花数有:" & N
End Sub第一题的两种方法各有一个命令按钮,共用一个文本框,第二题也一个命令按钮,两题共用一个标签
2013-07-20
展开全部
1.Private Sub Command1_Click(Index As Integer)
Dim x, y As Integer
Select Case Index
Case 0
x = Text1.Text
If x < 1 Then
y = x
Label1.Caption = y
ElseIf 1 <= x < 10 Then
y = 3 * x - 2
Label1.Caption = y
ElseIf x >= 10 Then
y = 4 * x - 12
Label1.Caption = y
End If
Case 1
End
End Select
End Sub2.Private Sub Command1_Click()
Dim a, b, c, d As Integer
a = Mid(Text1.Text, 1, 1)
b = Mid(Text1.Text, 2, 1)
c = Mid(Text1.Text, 3, 1)
If a ^ 3 + b ^ 3 + c ^ 3 = Val(Text1.Text) Then
Label2.Caption = Text1.Text
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "水仙花数:"
End Sub
Dim x, y As Integer
Select Case Index
Case 0
x = Text1.Text
If x < 1 Then
y = x
Label1.Caption = y
ElseIf 1 <= x < 10 Then
y = 3 * x - 2
Label1.Caption = y
ElseIf x >= 10 Then
y = 4 * x - 12
Label1.Caption = y
End If
Case 1
End
End Select
End Sub2.Private Sub Command1_Click()
Dim a, b, c, d As Integer
a = Mid(Text1.Text, 1, 1)
b = Mid(Text1.Text, 2, 1)
c = Mid(Text1.Text, 3, 1)
If a ^ 3 + b ^ 3 + c ^ 3 = Val(Text1.Text) Then
Label2.Caption = Text1.Text
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "水仙花数:"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |