Overall percentage change from successive changes
Given an array Arr which represent the percentage change. The task is to determine the Percentage increase after these percentage change.
Examples:
Input: arr[] = {10, 20, 30, 10} Output: Percentage change is = 88.76 % Input: arr[] = {20, 15, 9, 7} Output: Percentage change is = 60.94 %
Solution without successive change:-
let us take a number N = 120.
and percentage changes are given as, arr[] = {10, 20, 30, 10}
Now, if we first increase 120 by 10% i.e 120 * 1.1 We get N = 132
again if we increase it by 20% i.e 132 * 1.2 We get N = 158.4
again if we increase it by 30% i.e 158.4 * 1.3 We get N = 205.92
and lastly if we further increase it by 10% i.e 205.92 * 1.1 We get N = 226.51Now, Percentage change = (226.51 – 120) / 120 = 0.8876
percentage change = 0.8876 * 100 = 88.76 %
How does this formula work?
Let x be the initial value. After A% change, value of x becomes (x + x*A/100)
After successive B% change, value of x becomes (x + x*A/100) + (x + x*A/100)*B/100. So increment in x’s value is x*(A + B + A*B/100)/100. In terms of percentage, we can say that the value is incremented by (A + B + A*B/100)%
Approach:-
- Simply, Apply sucessive change formula between arr[0] and arr[1] and store the result in result variable
- Now, calculate successive change between result and arr[2] using above formula and store the result in result variable and so on..
- Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant
- Percentage increase in volume of the sphere if radius is increased by a given percentage
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Find the number after successive division
- Program to find the Discount Percentage
- Program to find the percentage of difference between two numbers
- Find Selling Price from given Profit Percentage and Cost
- Python | Percentage increase in the total surface area of the cuboid
- Program to find the rate percentage from compound interest of consecutive years
- Percentage increase in the volume of cuboid if length, breadth and height are increased by fixed percentages
- Find cost price from given selling price and profit or loss percentage
- Loss when two items are sold at same price and same percentage profit/loss
- Coin Change | DP-7
- Change K elements so that (a1^2 + a2^2 + …+ aN^2 ) <= (a1 + a2 +…+ aN) becomes true
- Change all even bits in a number to 0
Below is the implementation of the above approach:
C++
// C++ implementation of above approach #include <bits/stdc++.h> using namespace std; float successiveChange( int arr[], int N) { float var1, var2, result = 0; var1 = arr[0]; var2 = arr[1]; // Calculate successive change of 1st 2 change result = var1 + var2 + ( float (var1 * var2) / 100); // Calculate successive change // for rest of the value for ( int i = 2; i < N; i++) result = result + arr[i] + ( float (result * arr[i]) / 100); return result; } // Driver code int main() { int arr[] = {10, 20, 30, 10}; int N = sizeof (arr) / sizeof (arr[0]); // Calling function float result = successiveChange(arr, N); cout << "Percentage change is = " << result << " %" ; return 0; } |
Java
// Java implementation of above approach import java.io.*; class GFG { static float successiveChange( int arr[], int N) { float var1, var2, result = 0 ; var1 = arr[ 0 ]; var2 = arr[ 1 ]; // Calculate successive change of 1st 2 change result = var1 + var2 + ((var1 * var2) / 100 ); // Calculate successive change // for rest of the value for ( int i = 2 ; i < N; i++) result = result + arr[i] + ((result * arr[i]) / 100 ); return result; } // Driver code public static void main (String[] args) { int []arr = { 10 , 20 , 30 , 10 }; int N = arr.length; // Calling function float result = successiveChange(arr, N); System.out.println( "Percentage change is = " + result + " %" ); } } // This code is contributed by shs.. |
Python 3
# Python implementation of above approach def successiveChange(arr, N): result = 0 ; var1 = arr[ 0 ]; var2 = arr[ 1 ]; # Calculate successive change of 1st 2 change result = float (var1 + var2 + ( float (var1 * var2) / 100 )); # Calculate successive change # for rest of the value for i in range ( 2 , N): result = (result + arr[i] + ( float (result * arr[i]) / 100 )); return result; # Driver code arr = [ 10 , 20 , 30 , 10 ]; N = len (arr) ; # Calling function result = successiveChange(arr, N); print ( "Percentage change is = %.2f" % (result), "%" ); # This code is contributed # by Shivi_Aggarwal |
C#
// C# implementation of above approach using System; class GFG { static float successiveChange( int []arr, int N) { float var1, var2, result = 0; var1 = arr[0]; var2 = arr[1]; // Calculate successive change of 1st 2 change result = var1 + var2 + ((var1 * var2) / 100); // Calculate successive change // for rest of the value for ( int i = 2; i < N; i++) result = result + arr[i] + ((result * arr[i]) / 100); return result; } // Driver code public static void Main () { int []arr = {10, 20, 30, 10}; int N = arr.Length; // Calling function float result = successiveChange(arr, N); Console.WriteLine( "Percentage change is = " + result + " %" ); } } // This code is contributed by shs.. |
PHP
<?php // PHP implementation of above approach function successiveChange( $arr , $N ) { $result = 0; $var1 = $arr [0]; $var2 = $arr [1]; // Calculate successive change // of 1st 2 change $result = $var1 + $var2 + (( $var1 * $var2 ) / 100); // Calculate successive change // for rest of the value for ( $i = 2; $i < $N ; $i ++) $result = $result + $arr [ $i ] + (( $result * $arr [ $i ]) / 100); return $result ; } // Driver code $arr = array (10, 20, 30, 10); $N = count ( $arr ); // Calling function $result = successiveChange( $arr , $N ); echo "Percentage change is = " , $result , " %" ; // This code is contributed by shs.. ?> |
Percentage change is = 88.76 %
Recommended Posts:
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.