返回列表 發帖

040 一維陣列宣告

學會使用一維陣列:
  • 宣告方式
  • 宣告後直接指定陣列內容
  • 修改陣列內容
  • 讀取陣列內容

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int z[10] = {20, 0, 30, 0, 40, 0, 50, 0, 60, 0};
  7.                 z[1] = z[0] - 5;
  8.                 z[3] = z[2] - 5;
  9.                 z[5] = z[4] - 5;
  10.                 z[7] = z[6] - 5;
  11.                 z[9] = z[8] - 5;
  12.         cout << z[0] << " " << z[1] << " " << z[2] << " " << z[3] << " " << z[4] << " ";
  13.                 cout << z[5] << " " << z[6] << " " << z[7] << " " << z[8] << " " << z[9] << endl;
  14.         cout << endl;
  15.         system ("pause");
  16.         return 0;
  17. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int z[10] = {20,0,30,0,40,0,50,0,60,0};
  7.         z[1] = z[0] -5
  8.         z[3] = z[2] -5
  9.         z[5] = z[4] -5
  10.         z[7] = z[6] -5
  11.         z[9] = z[8] -5
  12.         cout << z[0] << " " << z[1] << " " << z[2] << " " << z[3] << " " <<  z[0] << " ";
  13.         cout << z[4] << " " << z[5] << " " << z[6] << " " << z[7] << " " <<  z[8] << " " << z[9] << " "
  14.         system ("pause");
  15.         return 0;
  16. }
複製代碼

TOP

返回列表