找回密碼
 註冊
搜索
熱搜: 活動 交友 discuz
查看: 1962|回覆: 0

[原創] 遞迴函數

[複製鏈接]
發表於 2007-5-18 10:37:15 | 顯示全部樓層 |閲讀模式
  1. #include<iostream>
  2. using namespace std ;
  3. double total = 0 ;
  4. double Sum(double X)
  5. {
  6.     total = total + X ;
  7.     X = X - 1 ;
  8.     if( X > 0)
  9.     {
  10.         return Sum(X) ;
  11.     }
  12.     else
  13.     {
  14.         return total ;
  15.     }
  16.     return 0 ;
  17. }


  18. int main()
  19. {
  20.     int X ;
  21.     cout << "Input Number " ;
  22.     cin >> X ;
  23.    
  24.     cout << Sum(X) ;
  25.    
  26.     system("PAUSE") ;
  27.     return 0 ;
  28. }
複製代碼
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Checking the Pageranks

Archiver|手機版|小黑屋|WEO

GMT+8, 2026-7-29 08:36 PM , Processed in 0.019052 second(s), 20 queries .

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

快速回復 返回頂部 返回列表