Calculate Reduced Mass in C language

First, we'll take input the values of masses of the first & second body, and then store them in the variables m1 and m2 respectively.

Then, we'll apply a condition, since mass can't be negative or less than zero.


After that, we'll apply the formula to calculate reduced mass.

Calculate Reduced Mass in C language 


#include<stdio.h>
void main()
{
//declaration of variable
float m1, m2, rm;
//getting the value of mass of first body
printf("Enter the Value Of m1");
scanf("%f",&m1);
//getting the value of mass of second body
printf("Enter the Value Of m2");
scanf("%f",&m2);
if(m1>0 && m2>0) //applying condition since mass can't be negative
{
// formula to calculate reduced mass
rm = ( (m1 * m2) / (m1+ m2) );
printf("With the mass of first body %f and mass of second body %f, the value of reduced mass is %f kg", m1, m2, rm);
}
else
{
printf("Mass can't be negative");
}
}
view raw reducedmass.c hosted with ❤ by GitHub

Related:



Comments

Popular posts from this blog

Pseudocode to Check, Number is Odd or Even

How to Create Marksheet in C

C Program to Calculate Acceleration