NeoYang 發表於 2007-5-18 10:37:15

遞迴函數

#include<iostream>
using namespace std ;
double total = 0 ;
double Sum(double X)
{
    total = total + X ;
    X = X - 1 ;
    if( X > 0)
    {
      return Sum(X) ;
    }
    else
    {
      return total ;
    }
    return 0 ;
}


int main()
{
    int X ;
    cout << "Input Number " ;
    cin >> X ;
   
    cout << Sum(X) ;
   
    system("PAUSE") ;
    return 0 ;
}
頁: [1]
查看完整版本: 遞迴函數

Checking the Pageranks