早教吧作业答案频道 -->其他-->
vb:输入m,n后再输入a数组的m个数和b数组的n个数,显示a、b中不同的数(如输入a组1.2.3.6,b组2.3.5,输出结果为1.6和5)PrivateSubFormClick()DimnAsByte,mAsByte,amAsByte,bnAsByte,a()AsInteger,b()AsIntegerm
题目详情
vb:输入m,n后再输入a数组的m个数和b数组的n个数,显示a、b中不同的数(如输入a组1.2.3.6,b组2.3.5,输出结果为1.6和5)
Private Sub Form_Click()
Dim n As Byte,m As Byte,am As Byte,bn As Byte,a() As Integer,b() As Integer
m = InputBox("a数组中元素个数"):n = InputBox("b数组中元素个数")
ReDim a(1 To m)
For am = 1 To m
a(am) = Val(InputBox("a(" & m & ")="))
Next am
ReDim b(1 To n)
For bn = 1 To n
a(bn) = Val(InputBox("a(" & n & ")="))
Next bn
For am = 1 To m
For bn = 1 To n
If a(am) - b(bn) 0 Then Exit For
Next bn
Print a(am);
Next am
For bn = 1 To n
For am = 1 To m
If b(bn) - a(am) 0 Then Exit For
Next am
Print b(bn);
Next bn
End Sub
做得是错的,还乱糟糟的,
Private Sub Form_Click()
Dim n As Byte,m As Byte,am As Byte,bn As Byte,a() As Integer,b() As Integer
m = InputBox("a数组中元素个数"):n = InputBox("b数组中元素个数")
ReDim a(1 To m)
For am = 1 To m
a(am) = Val(InputBox("a(" & m & ")="))
Next am
ReDim b(1 To n)
For bn = 1 To n
a(bn) = Val(InputBox("a(" & n & ")="))
Next bn
For am = 1 To m
For bn = 1 To n
If a(am) - b(bn) 0 Then Exit For
Next bn
Print a(am);
Next am
For bn = 1 To n
For am = 1 To m
If b(bn) - a(am) 0 Then Exit For
Next am
Print b(bn);
Next bn
End Sub
做得是错的,还乱糟糟的,
▼优质解答
答案和解析
libbo1974网友的做法是完全正确的,但没有指出程序中所有的错误,我来一个完整版吧.引用了libbo1974网友的程序,在此谢谢.还有为什么要用Byte这种数据类型呢,它只能表示0~255,改成了Integer类型.
Private Sub Form_Click()
Dim n As integer, m As Integer, am As Integer, bn As Integer, a() As Integer, b() As Integer
Dim isSame As Boolean
m = InputBox("a数组中元素个数")
n = InputBox("b数组中元素个数")
ReDim a(1 To m)
For am = 1 To m
a(am) = Val(InputBox("a(" & am & ")="))
Next
ReDim b(1 To n)
For bn = 1 To n
b(bn) = Val(InputBox("b(" & bn & ")="))
Next
For am = 1 To m
isSame = False
For bn = 1 To n
If a(am) - b(bn) = 0 Then isSame = True
Next
If isSame = False Then Print a(am)
Next
For bn = 1 To n
isSame = False
For am = 1 To m
If b(bn) - a(am) = 0 Then isSame = True
Next
If isSame = False Then Print b(bn)
Next
End Sub
Private Sub Form_Click()
Dim n As integer, m As Integer, am As Integer, bn As Integer, a() As Integer, b() As Integer
Dim isSame As Boolean
m = InputBox("a数组中元素个数")
n = InputBox("b数组中元素个数")
ReDim a(1 To m)
For am = 1 To m
a(am) = Val(InputBox("a(" & am & ")="))
Next
ReDim b(1 To n)
For bn = 1 To n
b(bn) = Val(InputBox("b(" & bn & ")="))
Next
For am = 1 To m
isSame = False
For bn = 1 To n
If a(am) - b(bn) = 0 Then isSame = True
Next
If isSame = False Then Print a(am)
Next
For bn = 1 To n
isSame = False
For am = 1 To m
If b(bn) - a(am) = 0 Then isSame = True
Next
If isSame = False Then Print b(bn)
Next
End Sub
看了vb:输入m,n后再输入a数组...的网友还看了以下:
电脑程序求三位数a的反序输出b输入格式:进一个数字a输出格式:仅输出结果b样例输入:275样例输出 2020-04-07 …
19世纪70年代以前,西方资本主义国家对中国经济侵略的方式是A.商品输出B.商品输出为主,资本输出 2020-05-13 …
数字转换机输入x→x的2次幂→-3输出→输入→6x→+1输出?若输入x=-1,最终输出结果是什么? 2020-06-05 …
入1,输出1/2,输入2,输出2/5,输入3.输出3/10,输入4,输出4/17当输出的数是122 2020-06-15 …
高手来做二元一次方程!1.给出下列程序:输入X→立方→xk→+b→输出,且已知当输入的x的值为1时 2020-07-13 …
若输入的x为1时,输出1若输入的x值为-1,输出值为-3则当输入的x等于0.5时,输出为多少!满意 2020-07-13 …
三变量的判偶逻辑电路为啥列出真值表后输入3个变量均为0输出为什么不是1而是0不是说输入为偶数个1, 2020-07-14 …
意输入一个整数N(0~999999),输出它的英文表达式用代码实现任务描述任意输入一个整数N(0~ 2020-07-20 …
python怎么调换一组数的顺序我有一组数D=[1,2,3,4,5,a,b,c]和index=5.想 2020-11-01 …
1、信息处理的六个基本环节除了采集、传输、加工外,还有:()A、存储、输入、输出B、存储、输入、打印 2020-11-22 …