早教吧作业答案频道 -->其他-->
用VB编程.1.输入一个整数n,计算n的阶乘.2.输入一个大于2的偶数,验证它可以表示成两个质数之和.3.生成一个序列,判断该序列是否为有序序列.
题目详情
用VB编程.
1.输入一个整数n,计算n的阶乘.
2.输入一个大于2的偶数,验证它可以表示成两个质数之和.
3.生成一个序列,判断该序列是否为有序序列.
1.输入一个整数n,计算n的阶乘.
2.输入一个大于2的偶数,验证它可以表示成两个质数之和.
3.生成一个序列,判断该序列是否为有序序列.
▼优质解答
答案和解析
三个文本框,三个控制按钮:
Private Function sushu(x As Integer) As Boolean
Dim i As Integer
For i = 2 To x - 1
If x Mod i = 0 Then Exit Function
Next i
sushu = True
End Function
Private Sub Command1_Click()
Dim n As Integer, i As Integer, x As Integer
n = InputBox("请出入n")
x = 1
For i = 1 To n
x = x * i
Next i
Text1.Text = CStr(x)
End Sub
Private Sub Command2_Click()
Dim i As Integer, x As Integer
x = InputBox("请输入一个大于2的数")
If x > 2 Then
For i = 1 To x / 2
If sushu(i) And sushu(x - i) Then
Text2.Text = x & "= " & i & " + " & x - i
Exit For
End If
Next i
Else
Text2.Text = "请重新输入一个大于2的数"
End If
End Sub
Private Sub Command3_Click()
Dim x As Integer, i As Integer, a() As Integer, j As Integer, k As Integer, m As Boolean, n As Boolean
Text3.Text = ""
x = InputBox("请输入序列长度")
ReDim a(x)
For i = 1 To x
a(i) = Int(Rnd * (99 - 10 + 1) + 10)
Text3.Text = Text3.Text & a(i) & " "
Next i
For i = 1 To x - 1
If a(i) < a(i + 1) Then j = j + 1
Next i
If j = x - 1 Then
m = True
Else
m = False
End If
For i = 1 To x - 1
If a(i) > a(i + 1) Then k = k + 1
Next i
If k = x - 1 Then
n = True
Else
n = False
End If
If m Or n = True Then
Text3.Text = Text3.Text & vbCrLf & "是有序数列"
Else
Text3.Text = Text3.Text & vbCrLf & "不是有序数列"
End If
End Sub
Private Function sushu(x As Integer) As Boolean
Dim i As Integer
For i = 2 To x - 1
If x Mod i = 0 Then Exit Function
Next i
sushu = True
End Function
Private Sub Command1_Click()
Dim n As Integer, i As Integer, x As Integer
n = InputBox("请出入n")
x = 1
For i = 1 To n
x = x * i
Next i
Text1.Text = CStr(x)
End Sub
Private Sub Command2_Click()
Dim i As Integer, x As Integer
x = InputBox("请输入一个大于2的数")
If x > 2 Then
For i = 1 To x / 2
If sushu(i) And sushu(x - i) Then
Text2.Text = x & "= " & i & " + " & x - i
Exit For
End If
Next i
Else
Text2.Text = "请重新输入一个大于2的数"
End If
End Sub
Private Sub Command3_Click()
Dim x As Integer, i As Integer, a() As Integer, j As Integer, k As Integer, m As Boolean, n As Boolean
Text3.Text = ""
x = InputBox("请输入序列长度")
ReDim a(x)
For i = 1 To x
a(i) = Int(Rnd * (99 - 10 + 1) + 10)
Text3.Text = Text3.Text & a(i) & " "
Next i
For i = 1 To x - 1
If a(i) < a(i + 1) Then j = j + 1
Next i
If j = x - 1 Then
m = True
Else
m = False
End If
For i = 1 To x - 1
If a(i) > a(i + 1) Then k = k + 1
Next i
If k = x - 1 Then
n = True
Else
n = False
End If
If m Or n = True Then
Text3.Text = Text3.Text & vbCrLf & "是有序数列"
Else
Text3.Text = Text3.Text & vbCrLf & "不是有序数列"
End If
End Sub
看了用VB编程.1.输入一个整数n...的网友还看了以下:
把公差d=2的等差数列{an}的各项依次插入等比数列{bn}中将{bn}按原顺序分成1项,2项,4 2020-04-05 …
CDMA码片序列CDMA这种信号传输方式的码片序列一般为0和1(或把0写成-1,把1写成+1),可 2020-06-24 …
用归并排序法对序列(98.36.-9.0.47.23.1.8)进行排序一共需要几趟归并可完成排序. 2020-06-28 …
有一个数群(1),(1,2),(1,2,3),……,(1,2,3,4,……,100),……,现在去 2020-07-06 …
23.一棵前序序列为1,2,3,4的二叉树,其中序序列不可能是().1.一棵前序序列为1,2,3, 2020-07-08 …
14.将3,4,5,……,100这98个数按某种顺序排成一行,使得第1个数能被1整除,第2个数能被 2020-07-09 …
(数据结构)有三个数字1,2,3,将它们构成二叉树,中序遍历序列为1,2,3的不同二叉树有种.可我 2020-07-10 …
图1给出一个用“当型”循环语句编写的程序:(1)该程序的算法功能是求式子的值.(2)用“直到型”循 2020-07-11 …
把1,2,3,…10这十个数按任意顺序排成一圈,在这一拳数中一定有相邻的三个数之和不把1,2,3, 2020-07-12 …
java编程2编写一个Java源程序(包含一个公共类),可以完成猜数游戏:(1)程序生成一个1~1 2020-07-17 …