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

TOP

返回列表