Computer Scientists are Pretty Pessimistic

Thursday 10 December 2015

Write a program that uses a function named wt_on_mn which takes as argument your weight on earth, converts it to that on the moon and displays it. The weight on earth is supposed to be entered through keyboard as a floating point number, and it is known that the moons gravity is 17 percent of the gravity of earth.



# We know that , weight = mass X gravity ; 

Suppose your weight on earth is 80.55 Newton, So, your mass is = (80.55/9.8) = 8.22 kg ; Now if we multiply your mass with moon_gravity we will find your weight on moon (Simple enough) . 

# Given that moon_gravity is 17% of the gravity of earth.

So, weight = mass X moon_gravity ; 
                 
= mass X ( (9.8 X 17) / 100 ) ; // We use this formula in our code

= 8.22 X ( (9.8 X 17) / 100 ) ;

 = 13.69 N ; 

Note : If you have any confusion about this formula follow #Intermediate Physics Book (Chapter Name - Gravity)


Solution ::

  1. #include <stdio.h> 
  2. void wt_on_mn(float mass); //Declare Function, this function calculate the weight and print it so here have no return type; 
  3. void main () 
  4.     float weight,mass; 
  5.     printf("Enter your weight on earth:\n"); 
  6.     scanf("%f",&weight); 
  7.     mass = (weight/9.8) ; 
  8.     wt_on_mn(mass); //Function called 
  9. void wt_on_mn(float mass) //Function
  10.     float w_on_moon; 
  11.     w_on_moon = mass * ((9.8*17)/100); 
  12.     printf("\nYour weight on moon is : %.2f\n",w_on_moon); 

Here, I do this code in very details. A problem can be solved in many way. So, you can modify this code as your wish.


Happy Coding.


No comments:

Post a Comment