/* C program to compute your weight on the nine planets. */ #include /* for printf and scanf */ #include /* for exit and EXIT_SUCCESS */ int main() { char *name[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; #define N (sizeof name / sizeof name[0]) /* the number of planets */ double factor[] = { /* gravity as a multiple of the earth's */ .27, /* Mercury */ .85, /* Venus */ 1.00, /* Earth */ .38, /* Mars */ 2.33, /* Jupiter */ .92, /* Saturn */ .85, /* Uranus */ 1.12, /* Neptune */ .44 /* Pluto */ }; double weight; /* your weight on earth */ int i; 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", name[i], factor[i] * weight); } return EXIT_SUCCESS; }