如何从数组中找到最大值和最小值? [英] how to find maximum and minimum value from an array?

查看:539
本文介绍了如何从数组中找到最大值和最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我有一个包含一组值(双精度型)的数组..我能知道如何从该数组中找到最大值和最小值吗?因为单击按钮时我想在文本框中显示这些值. .如果数组以字符串形式存储?如何将它们转换为双精度数组,然后用于方法?谢谢..

Hi..I have an array containing a group of values(type of double)..can I know how find maximum and minimum value from the array?because i want to display the values in textbox when the button is clicked..How if the array is stored in string form?How can i convert them into double array and then to be used for the methods?thanks in advance..

推荐答案


查找数组中最大值的代码:
Hi,
Code for Finding the Maximum Value in an Array:
maxValue = function (array) {
    mxm = array[0];
    for (i=0; i<array.length;>
       if (array[i]>mxm) {    
                mxm = array[i];    
       }
    }
    return mxm;
};


查找数组中最小值的代码:


Code for Finding the Minimum Value in an Array:

minValue = function (array) {
    mn = array[0];
    for (i=0; i<array.length;>        
        if (array[i]<mn){           
            mn = array[i];
        }
    }
    return mn;
};


使用LINQ,您要做的就是:
Using LINQ, all you need to do is:
int[] array1 = { 1, -1, -2, 0 };

// Find maximum number.
Console.WriteLine(array1.Max());

// Find minimum number.
Console.WriteLine(array1.Min());


参考: C#最大值,最小值 [


Refer: C# Max, Min[^]


这种方式.
This way.
Click here[^]


这篇关于如何从数组中找到最大值和最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆