- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int max = 10;
- int index = 0;
- int z[10] = {};
- bool isEnd = false;
-
- while(index < max && isEnd == false)
- {
- cout << "請輸入第" << index + 1 << "個數字:";
- cin >> z[index];
-
- if (z[index] == 0)
- {
- isEnd = true;
- }
-
- index++;
-
-
- }
-
- for (int j = 0; j < index - 1;j++)
- {
- for (int i = 0; i < index - 1; i++)
- {
- if (z[i] < z[i+1])
- {
- int tmp = z[i];
- z[i] = z[i+1];
- z[i+1] = tmp;
- }
- }
- }
-
-
- cout << "-----------------------" << endl;
- cout << "輸入的數字數量:" << index - 1 << "個" << endl;
- cout << "陣列內容如下:" << endl;
- for(int i = 0; i < index - 1; i++)
- {
- cout << i << "-" << z[i] << endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |