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

求1/n的时候出错了

Posted by lanzining at 2005-10-04 19:07:41 on Problem 1003
求1/n的时候出错了,这样求,1/n永远是0。
题目求得1/n是高精度的小数,直接sum+=1/n,sum是不会变的。
这样求就可以了:
double a=0;
 while(1){
	 a=a+0.000001;
	 if((1-a*n)<0.000001) //a=1/n,a是要求的数
		 return a;
         }

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