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
C++
#include <iostream>
using namespace std;
double findSpeed( double M1, double U1, double M2, double U2)
{
double momentum1 = M1 * U1;
double momentum2 = M2 * U2;
return (momentum1 + momentum2) / (M1 + M2);
}
int main()
{
double M1 = 4, U1 = 5, M2 = 6, U2 = 6;
cout << findSpeed(M1, U1, M2, U2) << endl;
return 0;
}
|
Time Complexity: O(1)
Space Complexity: O(1)
Share your thoughts in the comments
Please Login to comment...