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

小弟这段C++程序有问题么

Posted by Gerhut at 2006-09-16 12:10:24 on Problem 1650
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	long double inp;
	long int l;
	cin>>inp>>l;
	long int n,d;
	double minerr=inp;
	for(long i=l;i>0;i--)
	{
                long int j=(long int)(inp*i);
                long double err=fabsl((long double)(j)/(long double)(i)-inp);
                if(minerr>=err)
                {
			n=j;d=i;minerr=err;
		}
		j++;
		err=fabsl((long double)(j)/(long double)(i)-inp);
                if(minerr>=err)
                {
			n=j;d=i;minerr=err;
		}
	}
	cout<<n<<' '<<d<<endl;
	system("pause");
	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