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

不用想用double可以蒙混过关了,能有15个有效数字正确就不错了

Posted by frkstyc at 2005-03-31 19:27:13 on Problem 1001
In Reply To:求救!(请用纯小数测试,如:0.4321)为什么从某一位后的数字就不对了? Posted by:00 at 2005-03-31 17:39:40
> #include<iostream.h>
> #include<iomanip.h>
> #include<math.h>
> double R;
> int n,i,wide1,wide2;
> void computation(double,int);
> void main()
> {
> 	cin>>R>>n;
> 	computation(R,n);
> }
> void computation(double a,int b)
> {
> 	double x=pow(a*10000,n);
> 	for(i=0;;i++)
> 	{
> 		if(!floor(x/pow(10,i)))
> 			break;
> 	}
> 	wide1=i;
> 	for(i=1;;i++)
> 	{
> 		if(int(a*10000)%int(pow(10,i)))
> 			break;
> 	}
> 	wide2=(5-i)*n;
> 	cout<<".";
> 	for(i=0;i<4*n-wide1;i++)
> 		cout<<"0";
> 	for(i=0;i<wide2-4*n+wide1;i++)
> 	{
> 		cout<<int(x/pow(10,wide1-i-1));
> 		x-=int(x/pow(10,wide1-i-1))*pow(10,wide1-i-1);
> 	}
> 	cout<<endl;
> }

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