标题:[求助]一个问题"SUB 过程"
只看楼主
feng0325
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2007-9-19
 问题点数:0 回复次数:3 
[求助]一个问题"SUB 过程"
private sub f(a() as single,n as integer)
dim i as integer ,j as integer ,k as integer , t as single
for i=1 to n-1
k=i
for j=i+1 to n
if abs(a(j))>abs(a(k)) then k=j
next j
a(k)=a(i):a(i)=a(k)
next i
end sub
private sub command1_click()
dim x(5) as single
x(1)=5:x(2)=-7:x(3)=5:x(4)=12:x(5)=-3
call f(x,5)
print x(1);x(2);x(3);x(4);x(5)
end sub
结果是:5 -7 5 5 -3
我想问一下第四项为什么会是5??
搜索更多相关主题的帖子: SUB 
2007-11-06 19:24
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
得分:0 

我觉得你应该问第一项为什么是5....
Private Sub f(a() As Single, n As Integer)
Dim i As Integer, j As Integer, k As Integer, t As Single
Dim tmp As Single
For i = 1 To n - 1
k = i
For j = i + 1 To n
If Abs(a(j)) > Abs(a(k)) Then
tmp = a(k)
a(k) = a(j)
a(j) = tmp
End If
Next j
a(k) = a(i): a(i) = a(k)
Next i
End Sub

Private Sub command1_click()
Dim x(5) As Single
x(1) = 5: x(2) = -7: x(3) = 5: x(4) = 12: x(5) = -3
Call f(x, 5)
Print x(1); x(2); x(3); x(4); x(5)
End Sub


[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-11-06 19:30
feng0325
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2007-9-19
得分:0 
这个结果没什么不同呀??
2007-11-06 19:38
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
得分:0 
private sub command1_click()
dim x(5) as single
x(1)=5:x(2)=-7:x(3)=5:x(4)=12:x(5)=-3
call f(x,5)
print x(1);x(2);x(3);x(4);x(5)
end sub
结果是:5 -7 5 5 -3

老兄,拜托
x(1)=5:x(2)=-7:x(3)=5:x(4)=12:x(5)=-3

你结果:5 -7 5 5 -3
你看仔细了,没搞错?

[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-11-07 18:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-184018-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022165 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved