本帖最後由 李允軒 於 2014-4-19 14:59 編輯
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int z[20], a = {};
- cout << "請輸入等差數列的第一個數字:";
- cin >> z[0];
- cout << "請輸入等差數列的第二個數字:";
- cin >> z[1];
- a = z[1] - z[0];
- cout << "等差為" << a << endl;
- cout << "編號" << "\t"<< "內容" << endl;
- for (int i = 0; i < 20; i++)
- {
- z[i + 1] = z [i] + a;
- }
- for (int i = 0; i < 20; i++)
- {
- cout << i << "\t" << z[i] << endl;
- }
- system ("pause");
- return 0;
- }
複製代碼 |