Open In App

C++ Program to Find Speed of Combine Mass

Last Updated : 12 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

M_1.U_1 + M_2U_2 = M_3U_3+M_4.U_4

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

M_1.U_1+M_2.U_2 = (M_1+M_2)U_3

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

C++

// C++ program to find speed of mass by momentum
// conservation
#include <iostream>
using namespace std;
// funtcion to find speed of final mass
double findSpeed(double M1, double U1, double M2, double U2)
{
    // momentum for body 1
    double momentum1 = M1 * U1;
    // momentum for body 2
    double momentum2 = M2 * U2;
    return (momentum1 + momentum2) / (M1 + M2);
}
  
// Driver Code
int main()
{
  
    double M1 = 4, U1 = 5, M2 = 6, U2 = 6;
  
    cout << findSpeed(M1, U1, M2, U2) << endl;
    return 0;
}

                    

Output
5.6

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads