返回列表 發帖
  1. #include<iostream>
  2. using namespace std;
  3. int my_sum(int,int);
  4. int main()
  5. {
  6.     int x , y;
  7.     cout<<"請輸入第一個數:";
  8.     cin>>x;
  9.     cout<<"請輸入第二個數:";
  10.     cin>>y;
  11.     cout<<"兩數所有數字的總和"<<my_sum(x,y)<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
  15. int my_sum(int x,int y)
  16. {
  17.     int total=0, temp;
  18.     if (y<x)
  19.     {
  20.        temp=y;
  21.        y=x;
  22.        x=temp;           
  23.     }for(int i=x; i<=y; i++)
  24.     {
  25.        total=total+i;      
  26.     }
  27.     return total;
  28. }
複製代碼

TOP

返回列表