Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
756 B
4
Indexable
Never
#include <stdio.h>
#include <math.h>
struct sParticle{
    double mass; 
    double height;
};

double Bounce(struct sParticle p, double G){
    int v = sqrt(2 * G * p.height);
    if(v >= 2)
        return p.height * 0.9;
    else
        return p.height * 0.5;
}

int main(){
    int count = 0;
    struct sParticle particle;
    particle.mass = 1.0;
    particle.height = 1.0;
    double G;
    printf("Enter G: ");
    scanf("%lf", &G);
    printf("Initial height = 1\n");
    while(Bounce(particle,G) > 0.05){
        particle.height = Bounce(particle, G);
        printf("Height = %lf\n", particle.height);
        count ++;
    }
    count ++;
    printf("Height = %lf\n", Bounce(particle, G));
    printf("Total %d bounces", count);
    return 0;
}