返回列表 發帖
本帖最後由 徐楷恩 於 2023-6-20 20:24 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int i ,j ,f=0;
  8.     cout<<"請輸入第一個數: ";
  9.     cin>>i;
  10.     cout<<"請輸入第二個數: ";
  11.     cin>>j;
  12.     if(i<j)
  13.     {
  14.         for(int a=i;a<=j;a++)
  15.         f+=a;
  16.     }
  17.     else
  18.         {
  19.             for(int a=j;a<=i;a++)
  20.             f+=i ;   
  21.         }
  22.     cout<<"從"<<i<<"到"<<j<<"所有整數的總和為: "<<f<<endl<<endl;
  23.     goto re;
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表