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.4321)为什么从某一位后的数字就不对了?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator