C++ Program to Find Speed of Combine Mass
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++
// 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)
Contact Us