码迷,mamicode.com
首页 > 编程语言 > 详细

问题 1019: C语言程序设计教程(第三版)课后习题6.9

时间:2017-05-13 00:35:53      阅读:397      评论:0      收藏:0      [点我收藏+]

标签:under   .cpp   har   fine   过程   static   bsp   code   scan   

/********************************************************************
@file     Main.cpp
@date     2017-05-12 23:18:28
@author   Zoro_Tiger
@brief    问题 1019: C语言程序设计教程(第三版)课后习题6.9
          http://www.dotcpp.com/oj/problem1019.html
********************************************************************/
#include <cstdio>
#include <cmath>

#define TEST
#undef  TEST

int main(int argc, const char* argv[])
{

#ifdef TEST
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int height = 0, times = 0;
    while (scanf("%d%d", &height, &times) != EOF)
    {
        double last_height = height / static_cast<double>(pow(2.0, times)); //! (a/(b^times))

        double temp_height = static_cast<double>(height);
        double distance = temp_height;
        for (int i = 1; i < times; ++i) //!模拟落下弹起的过程
        {
            temp_height /= 2;
            distance += (temp_height * 2);
        }

        printf("%.2lf %.2lf\n", last_height, distance);
    }

    return 0;
}

 

问题 1019: C语言程序设计教程(第三版)课后习题6.9

标签:under   .cpp   har   fine   过程   static   bsp   code   scan   

原文地址:http://www.cnblogs.com/roronoa-zoro-zrh/p/6847729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!