
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Find 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
Advertisements