返回列表 發帖
本帖最後由 林宇翔 於 2014-4-26 17:38 編輯

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
                int z[10];
                int index = 0;
                int max = 10;
                bool isEnd = false;
                while(index < 10 && 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 < z[i+1])
                                {
                                 int tmp = z;
                                 z = z[i+1];
                                 z[i+1] = tmp;
                                }
                        }
                }
                cout << "-----------------------" << endl;
                cout << "輸入的數字數量:" << index << "個" << endl;
                cout << "陣列內容如下:" << endl;
                for(int x = 0; x < index - 1; x++)
                {
                        cout << x << " - " << z[x] << endl;
                }
               
        system ("pause");
        return 0;
}

TOP

返回列表