- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Golang Program to Find the Gravitational Force Acting Between Two Objects

## Steps

- Read both the masses and the distance between the masses and store them in separate variables.
- Initialize one of the variables to the value of gravitational constant, G.
- Then, the formula f=(G*m1*m2)/(r**2) is used to determine the force acting between the masses.
- Rounding off up to two decimal places, print the value of the force.

Enter the first mass: 1000000 Enter the second mass: 500000 Enter the distance between the centres of the masses: 20 Hence, the gravitational force is: 0.08 N | Enter the first mass: 90000000 Enter the second mass: 7000000 Enter the distance between the centres of the masses: 20 Hence, the gravitational force is: 105.1 N |

## Explanation

- User must enter the values for both the masses and the distance between the masses and store them in separate variables.
- One of the variables is initialised to the value of gravitational constant (G) which is equal to 6.673*(10**-11).
- Then, the formula: f=(G*m1*m2)/(r**2), where m1 and m2 are the masses and r is the distance between them, is used to determine the magnitude of force acting between the masses.
- The force calculated is rounded up to 2 decimal places and printed.

## Example

package main import ( "fmt" "math" ) func main(){ var a, b, r float64 fmt.Print("Enter the first mass: ") fmt.Scanf("%f", &a) fmt.Print("Enter the second mass: ") fmt.Scanf("%f", &b) fmt.Print("Enter the distance between the centres of the masses: ") fmt.Scanf("%f", &r) G:=6.673*(math.Pow(10, -11)) f:=(G*a*b)/(math.Pow(r, 2)) fmt.Printf("Hence, the gravitational force is: %.2f N", f) }

## Output

Enter the first mass: 1000000 Enter the second mass: 500000 Enter the distance between the centres of the masses: 20 Hence, the gravitational force is: 0.08 N

- Related Questions & Answers
- Python Program to Find the Gravitational Force Acting Between Two Objects
- Find objects between two dates in MongoDB?
- Python program to find difference between two timestamps
- Program to Find the Shortest Distance Between Two Points in C++
- Program to maximize the minimum force between balls in a bucket using Python
- Golang Program to find the parity of a given number.
- Golang Program to Find the Smallest Divisor of an Integer
- Golang Program to find the position of the rightmost set bit
- 8085 program to find smallest number between two numbers
- How to find the dot product of two pandas series objects?
- Program to find the minimum edit distance between two strings in C++
- Get the property of the difference between two objects in JavaScript
- How to decode JSON into objects in Golang?
- Golang Program to Find the Area of a Rectangle Using Classes
- Golang Program to check if two numbers are Amicable Numbers

Advertisements