返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int print(int, int);
  5. int main()
  6. {
  7.     int x, y;
  8.     cout<<"請輸入連續數列的第一個數: ";
  9.     cin>>x;
  10.     cout<<"請輸入連續數列的最後一個數: ";
  11.     cin>>y;
  12.    
  13.     print(x,y);
  14.     system("pause");
  15.     return 0;
  16. }
  17. int print(int x, int y)
  18. {
  19.     if(x<=y)
  20.     {
  21.          while(x<=y)
  22.          {
  23.                cout<<x<<endl;
  24.                x++;
  25.          }
  26.     }else
  27.     {
  28.          for(int i=x; i>=y; i--)
  29.               cout<<i<<endl;
  30.     }
  31. }
複製代碼

TOP

返回列表