C#語言————選擇結構
阿新 • • 發佈:2018-11-12
ole 選擇結構 brush sum write div 選擇 for light
int[] num = new int[] {23,76,54,87,51,12 }; //冒泡排序 for (int i = 0; i < num.Length - 1; i++) { for (int j = 0; j < num.Length - 1 - i; j++) { if (num[j] > num[j + 1]) { int sum = num[j]; num[j] = num[j + 1]; num[j + 1] = sum; } } } //選擇排序 for (int i = 0; i < num.Length - 1; i++) { for (int j = i + 1; j < num.Length; j++) { if (num[i] > num[j]) { int num1 = num[i]; num[i] = num[j]; num[j] = num1; } } }
//輸出語句 for (int i = 0; i < num.Length;i++ ) { Console.WriteLine(num[i]); }
C#語言————選擇結構