C++ program to find the quantity after mixture replacement


In this tutorial, we will be discussing a program to find the quantity of milk left after mixture replacement.

Let us suppose we have X litres of milk. From that, Y litres of milk is replaced with Y litres of water itself. This same procedure is done again and again Z number of times. Our task is to find the final amount of milk left in the container.

Finding the relation among the values between the repetitive operations, we find the formula for finding the amount of milk after Z number of operations to be

amount left = ((X-Y)/X)Z*X

Example

#include <bits/stdc++.h>
using namespace std;
//calculating the final amount of milk
float calc_milk(int X, int Y, int Z) {
   float result = 0.0, result1 = 0.0;
   result1 = ((X - Y) / (float)X);
   result = pow(result1, Z);
   result = result * X;
   return result;
}
int main() {
   int X = 13, Y = 2, Z = 5;
   cout << calc_milk(X, Y, Z) << endl;
   return 0;
}

OUTPUT

5.63884

Updated on: 21-Nov-2019

54 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements