vb编程几道小题~请各位帮忙!
1、循环语句的应用:求1到50的平方和,去掉7和13的倍数。2、多重循环语句的应用:打印三角形3、条件语句的应用:输入一个字符,自动判断该字符是字母字符、数字字符还是其他...
1、循环语句的应用:求1到50的平方和,去掉7和13的倍数。
2、多重循环语句的应用:打印三角形
3、条件语句的应用:输入一个字符,自动判断该字符是字母字符、数字字符还是其他字符;
4、条件语句的应用:输入x,y,z三个数,比较它们的大小并重新排列,使得x>y>z。
5、循环语句的应用:从键盘输入两个正整数,求它们的最大公约数
6、函数过程的应用:设计一个程序,计算c=m!/n!(m-n)! 要求:x!用一个函数过程实现 展开
2、多重循环语句的应用:打印三角形
3、条件语句的应用:输入一个字符,自动判断该字符是字母字符、数字字符还是其他字符;
4、条件语句的应用:输入x,y,z三个数,比较它们的大小并重新排列,使得x>y>z。
5、循环语句的应用:从键盘输入两个正整数,求它们的最大公约数
6、函数过程的应用:设计一个程序,计算c=m!/n!(m-n)! 要求:x!用一个函数过程实现 展开
4个回答
展开全部
1,
Private Sub Form_Click()
Dim a(1 To 50) As Integer
Dim sum As Long
Dim sumdel As Long
For i = 1 To 50
a(i) = i ^ 2
sum = sum + a(i)
Next
For i = 1 To 50
If a(i) Mod 7 = 0 Or a(i) Mod 13 = 0 Then
sumdel = sumdel + a(i)
End If
Next
Print "所求的和为:" & sum - sumdel
End Sub
3,
Private Sub Form_Click()
i = Asc(InputBox("请输入字符", "输入框"))
If i >= 48 And i <= 57 Then
MsgBox "你输入的是数字字符"
ElseIf (i >= 65 And i <= 90) Or (i >= 97 And i <= 122) Then
MsgBox "你输入的是字母字符"
Else
MsgBox "你输入的是其它字符"
End If
End Sub
4,
'通用的排序过程
Private Sub rank(n As Integer, a() As Long)
For i = 1 To n - 1
imin = i
For j = i + 1 To n
If a(j) > a(imin) Then imin = j
Next j
If imin <> i Then t = a(i): a(i) = a(imin): a(imin) = t
Next i
End Sub
Private Sub Form_click()
Dim s(1 To 3) As Long
For i = 1 To 3
s(i) = Val(InputBox("输入第i个数据"))
Next
Call rank(3, s())
For i = 1 To 3
List1.AddItem s(i)
Next
End Sub
5,
Private Sub Form_Click()
Dim m As Long
Dim n As Long
m = Val(InputBox("请输入m的值", "输入框"))
n = Val(InputBox("请输入n的值", "输入框"))
Print "最大公约数为:" & Max公约数(m, n)
End Sub
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数
Dim X As Long, Y As Long, K As Long
X = IIf(A >= B, A, B) 'x存入最大值
Y = IIf(A <= B, A, B) 'y 存入最小值
Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do
X = Y: Y = K
Loop
Max公约数 = Y
End Function
6,
'通用声明
Option Explicit
Dim m As Integer, n As Integer
Private Sub Form_Load()
Do
n = Val(InputBox("N:"))
m = Val(InputBox("M:"))
Loop Until n <= m
End Sub
Private Function jc(ByVal x As Integer) As Double
Dim i As Integer
Dim result As Double
result = 1
For i = 1 To x
result = result * i
Next i
jc = result
End Function
Private Sub Command1_Click()
Dim doufact As Double
doufact = jc(m) / (jc(n) * jc(m - n))
Text1.Text = Str(doufact)
End Sub
Private Sub Form_Click()
Dim a(1 To 50) As Integer
Dim sum As Long
Dim sumdel As Long
For i = 1 To 50
a(i) = i ^ 2
sum = sum + a(i)
Next
For i = 1 To 50
If a(i) Mod 7 = 0 Or a(i) Mod 13 = 0 Then
sumdel = sumdel + a(i)
End If
Next
Print "所求的和为:" & sum - sumdel
End Sub
3,
Private Sub Form_Click()
i = Asc(InputBox("请输入字符", "输入框"))
If i >= 48 And i <= 57 Then
MsgBox "你输入的是数字字符"
ElseIf (i >= 65 And i <= 90) Or (i >= 97 And i <= 122) Then
MsgBox "你输入的是字母字符"
Else
MsgBox "你输入的是其它字符"
End If
End Sub
4,
'通用的排序过程
Private Sub rank(n As Integer, a() As Long)
For i = 1 To n - 1
imin = i
For j = i + 1 To n
If a(j) > a(imin) Then imin = j
Next j
If imin <> i Then t = a(i): a(i) = a(imin): a(imin) = t
Next i
End Sub
Private Sub Form_click()
Dim s(1 To 3) As Long
For i = 1 To 3
s(i) = Val(InputBox("输入第i个数据"))
Next
Call rank(3, s())
For i = 1 To 3
List1.AddItem s(i)
Next
End Sub
5,
Private Sub Form_Click()
Dim m As Long
Dim n As Long
m = Val(InputBox("请输入m的值", "输入框"))
n = Val(InputBox("请输入n的值", "输入框"))
Print "最大公约数为:" & Max公约数(m, n)
End Sub
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数
Dim X As Long, Y As Long, K As Long
X = IIf(A >= B, A, B) 'x存入最大值
Y = IIf(A <= B, A, B) 'y 存入最小值
Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do
X = Y: Y = K
Loop
Max公约数 = Y
End Function
6,
'通用声明
Option Explicit
Dim m As Integer, n As Integer
Private Sub Form_Load()
Do
n = Val(InputBox("N:"))
m = Val(InputBox("M:"))
Loop Until n <= m
End Sub
Private Function jc(ByVal x As Integer) As Double
Dim i As Integer
Dim result As Double
result = 1
For i = 1 To x
result = result * i
Next i
jc = result
End Function
Private Sub Command1_Click()
Dim doufact As Double
doufact = jc(m) / (jc(n) * jc(m - n))
Text1.Text = Str(doufact)
End Sub
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
展开全部
1.dim sum as long
dim i as integer
for i= 1 to 50
if i mod 7<>0 and i mod 13<>0 then
sum=sum+i^2
end if
next i
dim i as integer
for i= 1 to 50
if i mod 7<>0 and i mod 13<>0 then
sum=sum+i^2
end if
next i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1,Dim s, a, n As Integer
s = 0
a = 1
Do Until a >= 50
s = s + a ^ 2
a = a + 1
For n = 1 To 7
If a = 7 * n Or a = 13 * n Then
Do While a = 7 * n Or a = 13 * n
a = a + 1
Loop
End If
Next n
Loop
Label1.Text = s
2,上课了,下次再给你。。呵呵。。。不好意思
s = 0
a = 1
Do Until a >= 50
s = s + a ^ 2
a = a + 1
For n = 1 To 7
If a = 7 * n Or a = 13 * n Then
Do While a = 7 * n Or a = 13 * n
a = a + 1
Loop
End If
Next n
Loop
Label1.Text = s
2,上课了,下次再给你。。呵呵。。。不好意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第四题(非条件句解法):仔细看看你的题目发现有点问题,是不是输入三个数排序,按从大到小排序然后输出。下面就是最简便的方法(VB2005):
Dim x,y,z as double
x=val(textbox1.text)
y=val(textbox2.text)
z=val(textbox3.text)
Dim a() as double = {x,y,z}
Array.Sort(a)
msgbox("三个数从大到小排序是:"&a(0)&"、"&a(1)&"、"&a(2))
========
条件句的话要判断很多句啊。慢慢写就出来了。。
Dim x,y,z as double
x=val(textbox1.text)
y=val(textbox2.text)
z=val(textbox3.text)
Dim a() as double = {x,y,z}
Array.Sort(a)
msgbox("三个数从大到小排序是:"&a(0)&"、"&a(1)&"、"&a(2))
========
条件句的话要判断很多句啊。慢慢写就出来了。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询