#include <stdio.h>
#include <string.h>
typedef struct
{
char name [20];
double diameter;
int moons;
double orbit;
double spin;
} planets_t;
void
print_planet (planets_t p)
{
printf ("------------------------------------------------------\n");
printf ("%s\n", p.name);
printf ("Diameter: %.1f km\n", p.diameter);
printf ("Number of moons: %d\n", p.moons);
printf ("Time to complete one orbit around the sun: %.1f years\n", p.orbit);
printf ("Time to complete one rotation on the axis: %.1f hours\n", p.spin);
printf ("------------------------------------------------------\n\n");
}
planets_t
get_planet (void)
{
planets_t pl;
printf ("Enter the planet's name: ");
scanf ("%s", pl.name);
printf ("Enter the planet's diameter in km: ");
scanf ("%lf", &pl.diameter);
printf ("How many moons orbit this planet? ");
scanf ("%d", &pl.moons);
printf ("How many years does it take for this planet to orbit the sun? ");
scanf ("%lf", &pl.orbit);
printf ("How many hours for one rotation around the axis? ");
scanf ("%lf", &pl.spin);
return (pl);
}
int
main (void)
{
planets_t planet, planets[10];
planet = get_planet ();
planets[2] = get_planet ();
print_planet (planets[2]);
print_planet (planet);
planets[0] = planet;
print_planet (planets[0]);
return(0);
}
Enter the planet's name: Earth
Enter the planet's diameter in km: 12000
How many moons orbit this planet? 1
How many years does it take for this planet to orbit the sun? 1
How many hours for one rotation around the axis? 24
Enter the planet's name: Saturn
Enter the planet's diameter in km: 120000
How many moons orbit this planet? 23
How many years does it take for this planet to orbit the sun? 29.7
How many hours for one rotation around the axis? 10.5
------------------------------------------------------
Saturn
Diameter: 120000.0 km
Number of moons: 23
Time to complete one orbit around the sun: 29.7 years
Time to complete one rotation on the axis: 10.5 hours
------------------------------------------------------
------------------------------------------------------
Earth
Diameter: 12000.0 km
Number of moons: 1
Time to complete one orbit around the sun: 1.0 years
Time to complete one rotation on the axis: 24.0 hours
------------------------------------------------------
------------------------------------------------------
Earth
Diameter: 12000.0 km
Number of moons: 1
Time to complete one orbit around the sun: 1.0 years
Time to complete one rotation on the axis: 24.0 hours
------------------------------------------------------