一個具有N個元素的數組,找出數組中的第二大的數

 

using System;
using System.Collections.Generic;
using System.Collections;

using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
             int[] number=new int[]{5679,4,36,67976,124,235,453,436,6589,0,5,6,346,457,34,3642};
    //也可以弄成自己輸入數據
    int first=number[0],second=number[0];
    for(int i=0;i<16;++i){
        if(number[i]>first){
            second=first;
            first=number[i];
        }else{
            if(number[i]>second)
                second=number[i];
            else{
                second = first==second ? number[i] : second;
            }
        }
    }
    Console.WriteLine("{0},{1}",first,second);

            Console.ReadKey();
        }
    }
}

 

 

http://topic.csdn.net/u/20110425/13/98426b84-e062-48f1-9d94-c9f4bcbfd123.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章