zoukankan      html  css  js  c++  java
  • 2006: C语言实验——拍皮球

    2006: C语言实验——拍皮球

    Time Limit: 1 Sec  Memory Limit: 64 MB
    Submit: 231  Solved: 162
    [Submit][Status][Web Board]

    Description

    小瑜3岁了,很喜欢玩皮球,看来今后喜欢打篮球的^_^。最近她发现球从手中落下时,每次落地后反跳回原高度的一半,再落下,每次球落地时数球跳了几次,数到n次时爸爸在边上喊停,问小瑜现在球到底总共走了多少距离,小瑜故作沉思状,爸爸又问接下来小球能跳多高啊,小瑜摇摇头,心想还没跳我怎么知道啊,难道爸爸是神啊!这时的你在边上出主意想给小瑜写个程序计算一下,因此任务就交给你啦!假设球的初始高度为h,计算第n次落地时球经过的距离,以及落地后反弹能有多高。

    Input

    输入数据有多组,第一行为数据的组数t,下面t行为t组数据,每行有两个数h和n,分别用空格分隔。

    Output

    输出第n次反弹时球经过的距离和球最后的高度,保留小数点后2位。

    Sample Input

    2
    100 1
    100.0 2
    

    Sample Output

    100.00 50.00
    200.00 25.00
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        float m,n,h,i,sum;
        scanf("%f",&m);
        while(m--)
        {
            scanf("%f %f",&h,&n);
            sum=h+2*h*(1-pow(0.5,n-1));
            h/=pow(2,n);
            printf("%.2f %.2f\n",sum,h);
        }
    }
    

      

    1,要加入头文件 math.h 
    2,pow(x,y);//其作用是计算x的y次方。x、y及函数值都是double型
    例:
    要计算2的5次方
    源代码如下:
    #include"stdio.h"
    #include"math.h"
    main()
    {
    long total;
    int x = 2, y = 5;
    total = pow(x,y); /*调用pow函数*/
    printf("%ld",total);
    getch();
    }

    getch

    1. getch函数在C语言中使用时需包含的头文件为 conio.h ,应写为#include<conio.h>
    2. 函数原型为:int getch(void);
    3. getch的功能:从标准输入设备(键盘)读入一个字符,不回显在显示器上.
    4. # include <stdio.h>
      # include <conio.h>
      int main()
      
      {
      
          char ch;
      
          printf("请输入一个字符: ");
      
          ch = getch();    //在输入字符的时候,屏幕上并看不到输入的字符
      
          printf("输入的字符是:%c ",ch);    //输出字符
      
          return 0;
      
      }
      

        

  • 相关阅读:
    ES6 Symbol类型 附带:Proxy和Set
    why updating the Real DOM is slow, what is Virtaul DOM, and how updating Virtual DOM increase the performance?
    React高级指南
    池(Pool)
    计算机网络Intro
    React基础
    CommonJS 与 ES6 的依赖操作方法(require、import)
    webpack初识(biaoyansu)
    关于时间安排贪心算法正确性的证明
    DP总结
  • 原文地址:https://www.cnblogs.com/mjn1/p/8745004.html
Copyright © 2011-2022 走看看