- #include<iostream>
- using namespace std;
- int my_sum(int, int);
- int main()
- {
- int x, y;
- cout<<"請輸入第一個數: ";
- cin>>x;
- cout<<"請輸入第二個數: ";
- cin>>y;
- cout<<"兩數間所有的總合為: "<<my_sum(x,y)<<endl;
- system("pause");
- return 0;
- }
- int my_sum(int x, int y)
- {
- int total=0, temp;
- if(y<x)
- {
- temp=y;
- y=x;
- x=temp;
- }
- for(int i=x; i<=y; i++)
- {
- total=total+i;
- }
- return total;
- }
複製代碼 |