VOOZH about

URL: https://www.geeksforgeeks.org/computer-science-fundamentals/cpp-program-to-find-speed-of-combine-mass/

⇱ C++ Program to Find Speed of Combine Mass - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C++ Program to Find Speed of Combine Mass

Last Updated : 12 Feb, 2024

A body with the mass M_1 and speed u_1 collides with the body of mass M_2 with speed u_2, and after collision, both bodies stick together and start moving. The surface is frictionless and no energy is lost during collision.

In this article, the task is to find the final speed of combined masses if both were initially in the same direction.

Example

Input:
M_1= 4 units, U_1=5 units
M_2 =6 units, U_2 =6 units

Output:
5.6 units


Input:
M_1= 3 units, U_1 =2 units,
M_2 =1 units, U_2 =6 units

Output:
3 units

C++ Program to Find Speed of Combine Mass

We can conserve linear momentum in this isolated system ,with the equation:

It is given that M_1 and M_2 sticks together and moves it will be:

We will make sum of initial momentum and divide with total mass to get speed of final system


Output
5.6

Time Complexity: O(1)
Space Complexity: O(1)


Comment