In: Computer Science
Code -
#include <iostream>
using namespace std;
//constant declare for GRAVITATIONAL constant
const double GRAVITATIONAL = 6.6742E-8;
//FUNCTION TO CALCULATE Gravitational FORCE
double gravitationalForce(double mass1, double mass2, double
distance){
//calculate Gravitational force
double gForce =
(GRAVITATIONAL*mass1*mass2)/(distance*distance);
return gForce;
}
int main()
{
//variable declare
double gForce,mass1,mass2,distance;
//ask user for first body mass
cout<<"Enter mass of first body "<<endl;
cin>>mass1;
//ask user for second body mass
cout<<"Enter mass of second body "<<endl;
cin>>mass2;
//ask use for distance between 2 bodies
cout<<"Enter distance between 2 bodies "<<endl;
cin>>distance;
//calculate gravitational force
gForce = gravitationalForce(mass1,mass2,distance);
//print the result
cout<<"Gravitational Force between 2 bodies is
"<<gForce;
return 0;
}
Screenshots -