Product of non | C ++ program to find the product of all non - repeated elements in an array ; Function to find the product of all non - repeated elements in an array ; sort all elements of array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findProduct ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int prod = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) prod = prod * arr [ i ] ; } return prod ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findProduct ( arr , n ) ; return 0 ; }