赞
踩
- #include <stdio.h>
- #include <stdlib.h>
- double paperFold(double thickness,int time){
- int i;
- double res=thickness;
- for(i=0;i<time;i++){
- res*=2;
- }
- return res;
- }
-
- int main()
- {
- double thickness = 7e-8;
- printf("%f\n",paperFold(thickness,51));
- return 0;
- }
double的精确度确实好很多,使用float得出的都是约数
C++
- #include <iostream>
-
- using namespace std;
-
- class PageFold{
- private:
- long double thickness;
- int times;
- public:
- PageFold(double thickness,int times){
- thickness = thickness;
- times = times;
- }
-
- long double calculate(){
- long double result = thickness;
- for(int i=0;i<times;i++){
- result*=2.0;//±ØÐëÓÃ*=
- }
- return result;
- }
- };
- int main()
- {
- long double thickness = 0.000000007;
- int times = 51;
- PageFold example(thickness,times);
- cout <<example.calculate()<< endl;
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。