/* timedil.c -- 100126 (sjd) Demonstrate time dilation at different velocities */ #include #include #define C +3.0e8 /* speed of light in m/s */ void splash(void); double tdiff(double v); int main() { double vel; /* velocity in c */ double dt; /* difference between moving clock and clock at rest */ splash(); printf(" Velocity Earth hours/spaceship hour\n"); printf(" --------------------------------------\n"); for (vel = 0.1; vel < 0.999; vel += 0.1) { printf(" %5.1fc%21.3f\n", vel, tdiff(vel)); } printf("\n"); system("pause"); return 0; } /* displays program splash screen */ void splash() { printf("This program displays the hours elapsed on a clock\n" "on earth compared to a clock on a spaceship moving\n" "at the velocity shown.\n\n"); } /* returns time dilation at vel v (given in tems of c) */ double tdiff(double v) { return 1.0 / sqrt(1.0 - ((v * C) * (v * C)) / ( C * C)); }