遞迴函數
#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]

