早教吧作业答案频道 -->其他-->
vb:编制通用sub过程f3,将single类型一维数组反序排列(如实参数组元素依次为1,5,7,调用后为7,5,1PrivateSubf3(a()AsSingle,iAsByte)DimnAsByte,kAsByte,tempAsSingleFori=1Toktemp=a(i)a(i)=a(k+1-i)a(k+
题目详情
vb:编制通用sub过程f3,将single类型一维数组反序排列(如实参数组元素依次为1,5,7,调用后为7,5,1
Private Sub f3(a() As Single,i As Byte)
Dim n As Byte,k As Byte,temp As Single
For i = 1 To k
temp = a(i)
a(i) = a(k + 1 - i)
a(k + 1 - i) = temp
Next i
End Sub
Private Sub Form_Click()
Dim n As Byte,a() As Single,i As Byte
n = InputBox("请输入元素个数")
ReDim a(1 To n)
For i = 1 To n
a(i) = Val(InputBox("a(" & i & ")="))
Next i
Call f3(a,i)
For i = 1 To n
Print a(i);
Next i
End Sub
我写的不对,哪个地方错了啊?
Private Sub f3(a() As Single,i As Byte)
Dim n As Byte,k As Byte,temp As Single
For i = 1 To k
temp = a(i)
a(i) = a(k + 1 - i)
a(k + 1 - i) = temp
Next i
End Sub
Private Sub Form_Click()
Dim n As Byte,a() As Single,i As Byte
n = InputBox("请输入元素个数")
ReDim a(1 To n)
For i = 1 To n
a(i) = Val(InputBox("a(" & i & ")="))
Next i
Call f3(a,i)
For i = 1 To n
Print a(i);
Next i
End Sub
我写的不对,哪个地方错了啊?
▼优质解答
答案和解析
Private Sub f3(a() As Single, k As Byte) ‘原来定义的i在循环体内做循环变量用了
Dim n As Byte, i As Byte, temp As Single ’原来定义的k没有赋值
For i = 1 To k/2 '只要交换一半,全交换的话,又交换回来了.
temp = a(i)
a(i) = a(k + 1 - i)
a(k + 1 - i) = temp
Next i
End Sub
还有Call f3(a, i)
应改为Call f3(a, n),此时i已经为n+1了.
Dim n As Byte, i As Byte, temp As Single ’原来定义的k没有赋值
For i = 1 To k/2 '只要交换一半,全交换的话,又交换回来了.
temp = a(i)
a(i) = a(k + 1 - i)
a(k + 1 - i) = temp
Next i
End Sub
还有Call f3(a, i)
应改为Call f3(a, n),此时i已经为n+1了.
看了 vb:编制通用sub过程f3...的网友还看了以下:
如何化简公式v平均=2v1v2/v1+v2?坐等.要每一步的过程.如v平=(S+S)/(S/V1+ 2020-05-16 …
1)有三个关系R,S和T如下 R(AB m1 n2) S(BC 13 35) T(ABC m13) 2020-05-17 …
在298K时,NaCl在水中的溶解度为26g100g水.如将1molNaCl溶解在1L水中,此溶解 2020-05-17 …
写一函数voidfun(char*s)实现如下单词倒序功能:如s为字符串“astFVsULLY”, 2020-07-20 …
对任意正整数x,设S(x)为x的所有数位上的数字之和,令T(x)为|S(x+2)-S(x)|.例如 2020-07-30 …
对于求集合种类的题目有什么方法(公式)?比如A={1,2,3,4,5,6},B={4,5,6,7} 2020-07-30 …
可数名词复数直接加S时,如果原单词既不是以清辅音结尾也不是因浊辅音结尾,+s后如何发音辅音的分类方法 2020-11-10 …
设M.N均为整数,记S为形如m+√2n(根号下2)的一切数所构成的集合,对于S中的任意两数X.Y,( 2020-11-19 …
软件中可数名词复数问题软件中的可数名词,有的带有s,有的没有s.比如说:常见的菜单中,File就没有 2020-11-28 …
谓语动词,think单数怎么表示?经常看到有些句子说,谓语动词用,单数,或者复数..请问,动词怎么变 2021-02-05 …