# Program to find gravitational force between two objects

Introduction to Gravitational Force

We know that gravity is universal. According to Newton’s Law of Universal Gravitation, all objects attract each other with a force of gravitational attraction. According to this law, the force of gravitational attraction is directly dependent upon the masses of both objects and inversely proportional to the square of the distance that separates their centers. On removing the proportionality sign, we add G, the Universal Gravitational Constant. This can be reduced to the following equation: F= Gravitation force of attraction between two objects in newton(N)
G=Universal Gravitational Constant( )

m1 and m2 = Mass of two objects(Kg)

r= separation in meters(m) between the objects,as measured from their centres of mass.

Examples:

Input: m1 = 20000000 kg
m2 = 4000000 kg
r = 15 m
Output : The Gravitational Force is:  23.73 N

Input: m1 = 5000000 kg
m2 = 900000 kg
r = 30 m
Output : The Gravitational Force is:  0.33 N


## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

The approach is simple. We will just use the formula mentioned in the Introduction.

 # Python code to find Gravitational Force  def force(m1, m2, r):      G = 6.673*(10**-11)      F = (G*m1*m2)/(r**2)         # Rounding to two digits after decimal      return round(F, 2)      # Driver Code   m1 = 5000000 m2 = 900000 r = 30  print("The Gravitational Force is: ", force(m1, m2, r), "N")

Output:

The Gravitational Force is:  0.33 N


My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.