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 centres. 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
The approach is simple. We will just use the formula mentioned in the Introduction.
// C++ code to find Gravitational Force #include <iostream> using namespace std;
float round( float F)
{ float value = ( int )(F * 100 + .5);
return ( float )value / 100;
} float force( double m1, double m2, double r)
{ float G;
G = 6.67 / 1e11;
float F;
F = (G * m1 * m2) / (r * r);
// Rounding to two digits after decimal
return round(F);
} // Driver code int main()
{ float m1, m2, r;
m1 = 5000000;
m2 = 900000;
r = 30;
cout << "The Gravitational Force is: "
<< force(m1, m2, r) << "N" ;
return 0;
} // This code is contributed by parthagarwal1962000 |
# Python3 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" )
|
<script> // JavaScript code to find Gravitational Force function round (F)
{ var value = (F * 100 + .5);
return value / 100;
} function force(m1, m2, r)
{ var G;
G = 6.67 / 1e11;
var F;
F = (G * m1 * m2) / (r * r);
// Rounding to two digits after decimal
return round(F);
} // Driver code var m1, m2, r;
m1 = 5000000;
m2 = 900000;
r = 30;
document.write( "The Gravitational Force is: " + force(m1, m2, r) + "N" );
// This code is contributed by shivanisinghss2110 </script> |
public class GravitationalForce {
public static float round( float F) {
float value = ( int )(F * 100 + 0.5 );
return ( float )value / 100 ;
}
public static float force( double m1, double m2, double r) {
float G = ( float ) ( 6.67 / 1e11);
float F = (G * ( float ) m1 * ( float ) m2) / (( float ) r * ( float ) r);
// Rounding to two digits after decimal
return round(F);
}
// Driver code
public static void main(String[] args) {
float m1, m2, r;
m1 = 5000000 ;
m2 = 900000 ;
r = 30 ;
System.out.println( "The Gravitational Force is: " + force(m1, m2, r) + "N" );
}
} |
using System;
public class GravitationalForce {
public static float Round( float F) {
float value = ( int )(F * 100 + 0.5);
return ( float )value / 100;
}
public static float Force( double m1, double m2, double r) {
float G = ( float ) (6.67 / 1e11);
float F = (G * ( float ) m1 * ( float ) m2) / (( float ) r * ( float ) r);
// Rounding to two digits after decimal
return Round(F);
}
// Driver code
public static void Main( string [] args) {
float m1, m2, r;
m1 = 5000000;
m2 = 900000;
r = 30;
Console.WriteLine( "The Gravitational Force is: " + Force(m1, m2, r) + "N" );
}
} |
Output
The Gravitational Force is: 0.33N