Replace every element of the array by product of all other elements | C ++ program to Replace every element by the product of all other elements ; Calculate the product of all the elements ; Replace every element product of all other elements ; Driver code ; Print the modified array .
#include " iostream " NEW_LINE using namespace std ; void ReplaceElements ( int arr [ ] , int n ) { int prod = 1 ; for ( int i = 0 ; i < n ; ++ i ) { prod *= arr [ i ] ; } for ( int i = 0 ; i < n ; ++ i ) { arr [ i ] = prod / arr [ i ] ; } } int main ( ) { int arr [ ] = { 2 , 3 , 3 , 5 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; ReplaceElements ( arr , n ) ; for ( int i = 0 ; i < n ; ++ i ) { cout << arr [ i ] << " ▁ " ; } return 0 ; }