| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 437 人关注过本帖
标题:[求助]程序有问题:想找出数组中两数相差在15以内的数
取消只看楼主 加入收藏
ljyxxzj
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-10-21
收藏
 问题点数:0 回复次数:3 
[求助]程序有问题:想找出数组中两数相差在15以内的数
想找出数组中两数相差在15以内的数,这些数为不合格数,但是运行不出来
请指教,程序如下,谢谢
Private Sub Command2_Click()
Dim bjh() As Variant
Dim tmax As Variant
bjh = Array(130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10)
tmax = 0
For i = LBound(bjh) To UBound(bjh) - 1
For j = i + 1 To UBound(bjh)
If (bjh(i) - bjh(j) >= 15) And (bjh(i) - bjh(j - 1) < 15) Then
If i - j > tmax Then
tmax = i - j
Print "不合格的有1--" & i & "," & j & "--" & UBound(bjh)
End If
End If
Print "tmax=" & tmax;
Next j
Next i
End Sub
2007-11-15 20:39
ljyxxzj
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-10-21
收藏
得分:0 

重发一下吧(数组给改了一下,那个不太好),说的可能不是很清楚,就是要求i-j的最大值,tmax就是这个最大值,要求(bjh(i) - bjh(j) >= 15) And (bjh(i) - bjh(j - 1) < 15),i-j以外的就算不合格了,这样应该明白了吧

Private Sub Command2_Click()
Dim bjh() As Variant
Dim tmax As Variant
bjh = Array(130, 125, 123, 120, 115, 80, 78, 72, 60, 40, 30, 20, 10)
tmax = 0
For i = LBound(bjh) To UBound(bjh) - 1
For j = i + 1 To UBound(bjh)
If (bjh(i) - bjh(j) >= 15) And (bjh(i) - bjh(j - 1) < 15) Then
If i - j > tmax Then
tmax = i - j
Print "不合格的有1--" & i & "," & j & "--" & UBound(bjh)
End If
End If
Print "tmax=" & tmax;
Next j
Next i
End Sub

2007-11-15 21:23
ljyxxzj
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-10-21
收藏
得分:0 
我想想吧,谢谢了
2007-11-15 22:25
ljyxxzj
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-10-21
收藏
得分:0 
做出来了,不管你们看不看的懂,还是发上来吧,呵呵
Private Sub Command2_Click() '相差15最多的刀
Dim bjh() As Variant
Dim tmax As Variant
bjh = Array(130, 125, 124, 123, 115, 80, 70, 60, 50, 40, 30, 20, 10)
tmax = 0
For i = LBound(bjh) To UBound(bjh) - 1
For j = i + 1 To UBound(bjh)
If (bjh(i) - bjh(j) <= 15) Then
If j - i > tmax Then
tmax = j - i

End If
End If
Next j
Next i
Print "tmax=" & tmax
Print "不合格刀有" & UBound(bjh) - tmax & "个"
For i = LBound(bjh) To UBound(bjh) - 1
For j = i + 1 To UBound(bjh)
If (bjh(i) - bjh(j) <= 15) And j - i = tmax Then
Print "i=" & i, "j=" & j
If i = 1 Then
Print ; "不合格刀有" & j + 1 & "--" & UBound(bjh)
End If
If i = 2 Then
Print ; "不合格刀有1" & "," & j + 1 & "--" & UBound(bjh)
End If
If i >= 3 Then
Print ; "不合格刀有1--" & i - 1 & "," & j + 1 & "--" & UBound(bjh)
End If
End If
Next j
Next i
End Sub
2007-11-15 23:16
快速回复:[求助]程序有问题:想找出数组中两数相差在15以内的数
数据加载中...
 
   



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

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