Overall percentage change from successive changes | C ++ implementation of above approach ; Calculate successive change of 1 st 2 change ; Calculate successive change for rest of the value ; Driver code ; Calling function
#include <bits/stdc++.h> NEW_LINE using namespace std ; float successiveChange ( int arr [ ] , int N ) { float var1 , var2 , result = 0 ; var1 = arr [ 0 ] ; var2 = arr [ 1 ] ; result = var1 + var2 + ( float ( var1 * var2 ) / 100 ) ; for ( int i = 2 ; i < N ; i ++ ) result = result + arr [ i ] + ( float ( result * arr [ i ] ) / 100 ) ; return result ; } int main ( ) { int arr [ ] = { 10 , 20 , 30 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; float result = successiveChange ( arr , N ) ; cout << " Percentage ▁ change ▁ is ▁ = ▁ " << result << " ▁ % " ; return 0 ; }