| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么递归的返回值总是0.5?请帮忙
#include<iostream>
using namespace std;
double length ( int n )
{
if ( n == 2 )
return 0.5;
else
return ( length(n-1) + 1/n );
}
int main()
{
double c;
int cnum;
cin >> c;
while ( c != 0.00 )
{
cnum = 2;
while ( length ( cnum ) < c )
cnum ++ ;
cout << cnum << "\tcard(s)\n";
cin >> c;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator