IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CLoops : Mission to the Moon
<04.02>
/* Mission to the Moon */
#include <stdio.h> #define TRANSIT 72 /* how long top get there (hours)*/ #define PERIOD 1.5 /* how long to do one orbit (hours) */ #define MISSION 10 /* how many orbits to do */ int main (void) { double time; int orbit; /* mission begins */ printf ("Mission to the Moon - Times in hours\n"); printf ("====================================\n"); time = 0.0; printf ("Time - %4.1lf - Mission begins\n", time); /* we are at the moon */ time = time + TRANSIT; printf ("Time = %4.1lf - At the moon\n", time); orbit = 1; /* doing the orbits around the Moon */ while (orbit <= MISSION) { time = time + PERIOD; printf ("Time = %4.1lf - %2d orbits completed\n", time, orbit); orbit = orbit + 1; } /* back to Earth */ time = time + TRANSIT; printf ("Time = %5.1lf - Mission complete.\n", time); return (0); }
Hergestellt in Deutschland / Made in Germany
Mission to the Moon - Times in hours ==================================== Time - 0.0 - Mission begins Time = 72.0 - At the moon Time = 73.5 - 1 orbits completed Time = 75.0 - 2 orbits completed Time = 76.5 - 3 orbits completed Time = 78.0 - 4 orbits completed Time = 79.5 - 5 orbits completed Time = 81.0 - 6 orbits completed Time = 82.5 - 7 orbits completed Time = 84.0 - 8 orbits completed Time = 85.5 - 9 orbits completed Time = 87.0 - 10 orbits completed Time = 159.0 - Mission complete.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland