In: Computer Science
Our weight on different planets in the solar system
will differ due to the varying size and mass of each of the
planets. Write a C program, weight.c, to compute the weight of a
200 pound person on the following planets, based on the data
below:
 
 
Planet  Percent of Earth Weigh ------ 
------------------------
Mercury              
37.8% Venus       90.7%
Mars        37.7%
Jupiter                  
236.0% Saturn      91.6%
Uranus      88.9%
Neptune     112.0%
 
 
 
The program should generate the following outputs:
 
 
Mercury: xxx.x   Venus: xxx.x    Mars:
xxx.x Jupiter: xxx.x  Saturn: xxx.x  Uranus: xxx.x
Neptune: xxx.x
 
 
 
Your program should right-justify the planet names and present the
output to one decimal place as shown above. Be sure to line up the
decimal points. Use the following guidelines to develop your
program:
 
 
Declare your variables with appropriate data types.
 Assign values to your variables.
 Perform your calculations.
 Generate appropriate output.
 
 
Points to Remember:  
Make sure you are creating a C program and not a C++ program. The
.c suffix to your source code will invoke the C compiler while the
.cpp suffix will invoke the C++ compile
Program
#include<stdio.h>
int main()
{   
    float weight=200;//weight in pound on
earth   
    float
mer_wt,ven_wt,mars_wt,jup_wt,sat_wt,urn_wt,nep_wt;  
    mer_wt=(37.8*weight)/100;
    ven_wt=(90.7*weight)/100;
    mars_wt=(37.7*weight)/100;
    jup_wt=(236.0*weight)/100;
    sat_wt=(91.6*weight)/100;
    urn_wt=(88.9*weight)/100;
    nep_wt=(112.0*weight)/100;
    printf("Weight of a 200 pound person in planet :
");
    printf("\n%10s%.1f","Mercury:",mer_wt);
    printf("\n%10s%.1f","Venus:",ven_wt);
    printf("\n%10s%.1f","Mars:",mars_wt);
    printf("\n%10s%.1f","Jupiter:",jup_wt);
    printf("\n%10s%.1f","Saturn:",sat_wt);
    printf("\n%10s%.1f","Uranus:",urn_wt);
    printf("\n%10s%.1f","Neptune:",nep_wt);
}
Output
Weight of a 200 pound person in planet :
Mercury:75.6
    Venus:181.4
     Mars:75.4
Jupiter:472.0
   Saturn:183.2
   Uranus:177.8
Neptune:224.0