一个球从100米高度自由落下

一个球从100米高度自由落下,第1张

题目:一球从100米高度自由落下,每弯瞎次落地后反跳回原高度的一半;再落下,埋圆空求它在

第10次落地时,共经过多少米?第10次反d多高?

1.程序分析:见下面注释

2.程序源代码:

#include "stdio.h"

#include "stdio.h"

main()

{

float sn=100.0,hn=sn/腔运2

int n

for(n=2n<=10n++)

{

sn=sn+2*hn/*第n次落地时共经过的米数*/

hn=hn/2/*第n次反跳高度*/

}

printf("the total of road is %f\n",sn)

printf("the tenth is %f meter\n",hn)

getch()

}

这个是WIN-TC的教程,如果你用C++编译器,不用打最后的getch()

#include <iostream>

#include <math.h>

#define pi 3.1415926

同学,求质量必须有密度

#include <iostream>

#include <math.h>

#define pi 3.1415926

void main()

{

double radius = 0

double density = 0

std::cout <<"半径:"

std::cin >>radius

std::cout <<"密度慎闭睁:"

std::cin >>density

double area = 4 * pi * pow(radius, 2)

std::cout <<态迟 "表面积:" <<area <<std::endl

double volume = 4 * pi * pow(radius, 3)

std::cout <<"体积:" <<volume <<std::endl

double quality = density * volume

std::cout <<"宽岁质量:" <<quality <<std::endl

}

 

 

要制造那种效果只需要大约 30 行 Java 代卖戚橡码:

import javax.swing.*

import java.awt.*

import java.awt.geom.*

class RollingBall extends JPanel {

    Ellipse2D.Float ball = new Ellipse2D.Float( -100, 100, 50, 50 )

    public void paintComponent( Graphics g ) {

        super.paintComponent( g )

        Graphics2D g2 = ( Graphics2D ) g

        // Draw the ball

        g2.fill( ball )

        // Draw the rotating ellipse by skewing the Device Space

        double angdeg =     // One rotation per ball's travelling over its perimeter

            ball.x++ % ( Math.PI * ball.width ) / ( Math.PI * ball.width ) * 360

        g2.rotate( Math.toRadians( angdeg ), ball.getCenterX( ), ball.getCenterY( ) )

        g2.scale( .5, 1 )

        g2.translate( ball.getCenterX( ), 0 )

        g2.setColor( Color.gray )

        g2.fill( ball )

    }

    public void roll( ) throws Exception {

        while( true ) {

            repaint( )

            Thread.sleep( 8 )

   中旁     }

    }

    public static void main( String[ ] args ) throws Exception {

        JFrame f = new JFrame( )

        RollingBall rb = new RollingBall( )

    仔枝    f.setSize( 999, 185 )

        f.getContentPane( ).add( rb )

        f.setVisible( true )

        rb.roll( )

    }

}

 

 

 


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8263669.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存