本帖最後由 李東諺 於 2023-6-20 20:18 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int x,y,sum=0;
- cout<<"請輸入第一個數: ";
- cin>>x;
- cout<<"請輸入第二個數: ";
- cin>>y;
- if(x<y)
- {
- for(int i=x; i<=y; i++)
- sum+=i;
- }else
- {
- for(int i=y; i<=x; i++)
- sum+=i;
- }
- cout<<"從"<<x<<"到"<<y<<"所有整數的總合為: "<<sum<<endl<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- cin>>i;
- cout<<"請輸入一個整數 "<<endl;
- cin>>j;
- cout<<"請輸入一個整數 "<<endl;
- int a=0;
- for(float i=0; i<=i+j; 1++)
- {
- for(float j=0; j<=i+j; j++)
- {
- cout<<"從 到 之間的數總和為: "<<j+i<<endl;
- }
- }
- goto re;
- cout<<""<<a<<endl;
- system("pause");
- return 0;
- }
複製代碼 回復 1# 陳育霖 |