Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么递归的返回值总是0.5?请帮忙

Posted by scuttemp at 2009-01-12 21:49:41 on Problem 1003
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator