#include #include int main() { typedef struct { char *name; /* name of the planet */ double factor; /* how many times stronger its gravity is than earth's */ } planet_t; planet_t a[] = { {"Mercury", .27}, {"Venus", .85}, {"Earth", 1.00}, {"Mars", .38}, {"Jupiter", 2.33}, {"Saturn", .92}, {"Uranus", .85}, {"Neptune", 1.12}, {"Pluto", .44} }; #define N (sizeof a / sizeof a[0]) /* the number of planets */ double weight; int i; planet_t *p; printf("Please type your weight: "); scanf("%lf", &weight); printf("On each planet, your weight would be\n"); for (i = 0; i < N; ++i) { printf("%-11s %6.2f\n", a[i].name, weight * a[i].factor); } for (p = a; p < a + N; ++p) { printf("%-11s %6.2f\n", p->name, weight * p->factor); } return EXIT_SUCCESS; }