返回列表 發帖
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <math.h>

  4. using namespace std;

  5. int main() {
  6.   float x, y, a=0;
  7.   bool run = true;
  8.   string con;
  9.   while (run) {
  10.     a=0;
  11.     cout << "請輸入數字1:";
  12.     cin >> x;
  13.     cout << "請輸入數字2:";
  14.     cin >> y;
  15.     for (int i=x; i <= y; i++) {
  16.       a = a + i;
  17.       
  18.     }
  19.     cout << "從" << x << "加到" << y << "為" << a <<endl;

  20.     cout << "要繼續請打1:";
  21.     cin >> con;
  22.     if (con != "1") {
  23.       break;
  24.     }
  25.     system("cls");
  26.   }
  27.   system("pause");
  28.   return 0;
  29. }
複製代碼

TOP

返回列表