| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1511 人关注过本帖
标题:c#for..if语句
只看楼主 加入收藏
书虫zz
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-12-15
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
c#for..if语句
float[] c = new float[18];
        float[]c1 = new float[18];
        double a,b,q,x,x1,q1;
        float d1, d2, d3, o,o1 ;
        int p,p1;
        d1 = float.Parse(GZYL.SelectedValue);
        d2 = float.Parse(LLTL.SelectedValue);
        d3 = float.Parse(SB.SelectedValue);
        a = Math.Sqrt(d2/d1);
        a = 35.7 * a;
        b = Math.Sqrt((d3 - 1) / d3);
        b = a * b;
        GJ.Text = a.ToString("f2");
        HSGJ.Text = b.ToString("f2");
 o = float.Parse(GJ.Text);
        c[0] = 25;
        c[1] = 32;
        c[2] = 40;
        c[3] = 50;
        c[4] = 63;
        c[5] = 80;
        c[6] = 100;
        c[7] = 125;
        c[8] = 160;
        c[9] = 200;
        c[10] = 220;
        c[11] = 250;
        c[12] = 280;
        c[13] = 320;
        c[14] = 360;
        c[15] = 400;
        c[16] = 450;
        c[17] = 500;
        q = Math.Abs(o - c[0]);
        for (int i = 0; i < 18; i++)
        {
            p = 0;
            c[i] = Math.Abs(o - c[i]);
            if (c[i] >= q)
            {
                q = q;
            }
            else
                q = c[i];
                p = i;        
        }
        x = c[p];
        GJ.Text = x.ToString("f2");
想最后提取出来这个i,使x=c[p]的值,但是x = c[p];标红,显示p未赋值,放进for语句里面没有问题,但是我就是想通过这个语句找到圆整的值的,大神们帮忙看看应该怎么写?
搜索更多相关主题的帖子: double 
2016-12-27 15:54
zbjzbj
Rank: 12Rank: 12Rank: 12
来 自:郑州
等 级:贵宾
威 望:52
帖 子:633
专家分:3045
注 册:2011-4-22
收藏
得分:20 
           q = Math.Abs(o - c[0]);
            for (p = 0; p < 18; p++)
            {
                c[i] = Math.Abs(o - c[p]);
                if (c[p] < q)
                    q = c[p];
            }
            x = q;
            GJ.Text = x.ToString("f2");
        }
    }

[此贴子已经被作者于2016-12-28 11:48编辑过]

2016-12-28 11:43
快速回复:c#for..if语句
数据加载中...
 
   



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

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