Program to find the quantity after mixture replacement
Given a container that has X liters of milk. Y liters of milk is drawn out and replaced with Y liters of water. This operation is done Z times. The task is to find out the quantity of milk left in the container.
Examples:
Input: X = 10 liters, Y = 2 liters, Z = 2 times Output: 6.4 liters Input: X = 25 liters, Y = 6 liters, Z = 3 times Output: 10.97 liters
Formula:-

Below is the required implementation:
C++
// C++ implementation using above formula #include <bits/stdc++.h> using namespace std; // Function to calculate the Remaining amount. float Mixture(int X, int Y, int Z) { float result = 0.0, result1 = 0.0; // calculate Right hand Side(RHS). result1 = ((X - Y) / (float)X); result = pow(result1, Z); // calculate Amount left by // multiply it with original value. result = result * X; return result; } // Driver Code int main() { int X = 10, Y = 2, Z = 2; cout << Mixture(X, Y, Z) << " litres"; return 0; } |
chevron_right
filter_none
Java
// Java code using above Formula. import java.io.*; class GFG { // Function to calculate the // Remaining amount. static double Mixture(int X, int Y, int Z) { double result1 = 0.0, result = 0.0; // calculate Right hand Side(RHS). result1 = ((X - Y) / (float)X); result = Math.pow(result1, Z); // calculate Amount left by // multiply it with original value. result = result * X; return result; } // Driver Code public static void main(String[] args) { int X = 10, Y = 2, Z = 2; System.out.println((float)Mixture(X, Y, Z) + " litres"); } } // This code is contributed // by Naman_Garg |
chevron_right
filter_none
Python 3
# Python 3 implementation using # above formula # Function to calculate the # Remaining amount. def Mixture(X, Y, Z): result = 0.0 result1 = 0.0 # calculate Right hand Side(RHS). result1 = ((X - Y) / X) result = pow(result1, Z) # calculate Amount left by # multiply it with original value. result = result * X return result # Driver Code if __name__ == "__main__": X = 10 Y = 2 Z = 2 print("{:.1f}".format(Mixture(X, Y, Z)) + " litres") # This code is contributed by ChitraNayal |
chevron_right
filter_none
C#
// C# code using above Formula. using System; class GFG { // Function to calculate the // Remaining amount. static double Mixture(int X, int Y, int Z) { double result1 = 0.0, result = 0.0; // calculate Right hand Side(RHS). result1 = ((X - Y) / (float)X); result = Math.Pow(result1, Z); // calculate Amount left by // multiply it with original value. result = result * X; return result; } // Driver Code public static void Main() { int X = 10, Y = 2, Z = 2; Console.WriteLine((float)Mixture(X, Y, Z) + " litres"); } } // This code is contributed // by Akanksha Rai(Abby_akku) |
chevron_right
filter_none
PHP
<?php // PHP implementation of above formula // Function to calculate the // Remaining amount. function Mixture($X, $Y, $Z) { $result = 0.0; $result1 = 0.0; // calculate Right hand Side(RHS). $result1 = (($X - $Y) / $X); $result = pow($result1, $Z); // calculate Amount left by // multiply it with original value. $result = $result * $X; return $result; } // Driver Code $X = 10; $Y = 2; $Z = 2; echo Mixture($X, $Y, $Z), " litres"; // This code is contributed // by Sanjit_Prasad ?> |
chevron_right
filter_none
Output:
6.4 litres
Recommended Posts:
- Find amount to be added to achieve target ratio in a given mixture
- Next greater Number than N with the same quantity of digits A and B
- Smallest length string with repeated replacement of two distinct adjacent
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n
- Program to find the sum of a Series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2)
- Program to find the last two digits of x^y
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Program to find the sum of a Series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
- Program to find LCM of two numbers
- Program to find GCD or HCF of two numbers
- Program to find the value of tan(nΘ)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



