Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The gravitational attractive force between two bodies with masses and separated

ID: 3796171 • Letter: T

Question

The gravitational attractive force between two bodies with masses and separated by a center-to-center distance is given by the following formula: F = G m1 * m2 /r^2 Where is the universal gravitational constant: G = 6.67384 * 10 ^-11 m^3/(kg. s) Write a function that takes arguments for the masses of the two bodies and the distance between them and returns the gravitational force between them. You should use a locally defined constant variable G for the universal gravitational constant . Test your function to find the gravitational force with the earth moon data below. Example data : Mearth = 5.97219 x 1024 kg Mmoon = 7.34767 x 1022 kg Earth-moon distance (average) = 363104 x 103 m Fg = 2.22 x 1020 N Use the earth moon data to verify your function. 2nd part: Now improve your program by embedding your function in a complete program that asks the user to enter input for the masses and separation distance, and then calls your function to compute this. Finally, your program should allow the user to repeat this calculation as many times as they wish.

Explanation / Answer

//It is a c program to find a gravitational force between any two bodies
#include<stdio.h>
#include<math.h>
#define G 6.67384*pow(10.0,-11)
double gravitational_force(double mass1,double mass2,double distance);
main(){
   int option;
   double force,mass1,mass2,distance;
   double Mmoon=7.34767*pow(10,22),Mearth=5.97219*pow(10,24),MEdistance=363104*pow(10,3);
   do{
       printf(" 1.Test the Function using given earth and moon masses and distance between them");
       printf(" 2.Find the gravitational force between any two bodies");
       printf(" 3.Exit");
       printf(" Choose your option:");
       scanf("%d",&option);
       switch(option){
           case 1:
               force=gravitational_force(Mmoon,Mearth,MEdistance);
               printf(" The Gravitational force between moon and earth is:%.2e N",force);
               break;
           case 2:
               printf(" Enter the mass of the first body(in KG):");
               scanf("%f",&mass1);
               printf(" Enter the mass of the second body(in KG):");
               scanf("%f",&mass2);
               printf(" Enter the distance between two bodies(in meters):");
               scanf("%f",&distance);
               force=gravitational_force(mass1,mass2,distance);
               printf(" The gravitational force between given two bodies is:%e N",force);
               break;
           case 3:
               printf(" Thank you sir... Good bye");
               break;
           default:
               printf(" Invalid input....");
       }
       }while(option!=3);
       return 0;
}
double gravitational_force(double mass1,double mass2,double distance){
   double force;
   force=(G*mass1*mass2)/(pow(distance,2));
   return force;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote