| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1454 人关注过本帖
标题:求VB挂轮比代码
只看楼主 加入收藏
hl2388817942
Rank: 2
等 级:论坛游民
帖 子:9
专家分:10
注 册:2016-1-6
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
求VB挂轮比代码
比如,text1.text,是个double,比如是0.8745865231,求(A/B)*(C/D),A,B,C,D均是30到100的整数,要求输出(A/B)*(C/D)最接近text1.text里的数值,然后输出一个(A/B)*(C/D)

比如最终输出52/68*86/61

谢谢大侠
搜索更多相关主题的帖子: double 
2016-01-11 22:14
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:10 
(51/55)*(83/88)=.874586776859504

Dim a As Long, b As Long, c As Long, d As Long
Dim m As Double, n As Double
Dim k As Double

Dim a1 As Long, b1 As Long, c1 As Long, d1 As Long
Dim m1 As Double


k = 1
For a = 30 To 100
For b = 30 To 100
For c = 30 To 100
For d = 30 To 100
m = (a / b) * (c / d)
n = Abs(m - 0.8745865231)
If n < k Then
    k = n
    a1 = a
    b1 = b
    c1 = c
    d1 = d
    m1 = m
End If
Next d
Next c
Next b
Next a

Print "("; a1; "/"; b1; ")*("; c1; "/"; d1; ")="; m1
Debug.Print "(" & a1 & "/" & b1 & ")*(" & c1 & "/" & d1 & ")=" & m1

授人于鱼,不如授人于渔
早已停用QQ了
2016-01-12 21:43
hl2388817942
Rank: 2
等 级:论坛游民
帖 子:9
专家分:10
注 册:2016-1-6
收藏
得分:0 
(51/55)*(83/88)=.874586776859504

Dim a As Long, b As Long, c As Long, d As Long
Dim m As Double, n As Double
Dim k As Double

Dim a1 As Long, b1 As Long, c1 As Long, d1 As Long
Dim m1 As Double


k = 1
For a = 30 To 100
For b = 30 To 100
For c = 30 To 100
For d = 30 To 100
m = (a / b) * (c / d)
n = Abs(m - 0.8745865231)
If n < k Then
    k = n
    a1 = a
    b1 = b
    c1 = c
    d1 = d
    m1 = m
End If
Next d
Next c
Next b
Next a

Print "("; a1; "/"; b1; ")*("; c1; "/"; d1; ")="; m1
Debug.Print "(" & a1 & "/" & b1 & ")*(" & c1 & "/" & d1 & ")=" & m1


这个代码,我是在窗体有个text1.text,然后在text。text中输入实数,一般是小数点后七位,然后然后输出挂轮比,要求误差小于0.0002.这个程序不运行,大侠,看看应该怎么写,谢谢!
2016-01-17 12:51
快速回复:求VB挂轮比代码
数据加载中...
 
   



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

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