首页 > 代码库 > C# foreach,等量代换,冒泡排序

C# foreach,等量代换,冒泡排序

foreach:


        foreach (int h in a) //可以将数组读出来(自动遍历数组)
                {
                    Console.WriteLine(h);
                }

 

等量代换: 用一种量(或一种量的一部分)来代替和它相等的另一种量(或另一种量的一部分)。

 

 

            //需要有个中间变量来倒
            int a = 3, b = 5;
            int c;
            c = a;
            a = b;
            b = a;

 

冒泡排序

 

            int[] shu = new int[10];
            for (int i = 0; i < 10; i++)
            {
                shu[10] = Convert.ToInt32(Console.ReadLine());
            }
            for (int j = 0; j < 10 - 1; j++)
            {
                for (int i = j; i < 10; i++)
                {
                    if (shu[j] < shu[i])
                    {
                        int zhong = 0;
                        shu[i] = shu[j];
                        shu[j] = zhong;
                    }
                }
            }

C# foreach,等量代换,冒泡排序