From 3549fe821b625a2628baa37e01decd9040256180 Mon Sep 17 00:00:00 2001 From: "Amisha.Sahu" <115696152+Amisha2093@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:06:56 +0530 Subject: [PATCH] Add equilibriumpoint.cpp Adding a C++ program to find the equilibrium point in an array --- .../C++ Programs/Array/equilibriumpoint.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Program's_Contributed_By_Contributors/C++ Programs/Array/equilibriumpoint.cpp diff --git a/Program's_Contributed_By_Contributors/C++ Programs/Array/equilibriumpoint.cpp b/Program's_Contributed_By_Contributors/C++ Programs/Array/equilibriumpoint.cpp new file mode 100644 index 0000000000..4e22b1b53b --- /dev/null +++ b/Program's_Contributed_By_Contributors/C++ Programs/Array/equilibriumpoint.cpp @@ -0,0 +1,33 @@ +// Equilibrium Point +// Find an equilibrium point such that sum of elements before it is equal to sum of elements after it. + +#include +using namespace std; +#define eff ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define vi vector + +signed main(){ + eff; + int n; + cin>>n; + vi v(n); + for(int i = 0; i < n; i++) + cin>>v[i]; + + int sum = accumulate(v.begin(), v.end(), 0); + int left = 0; + for(int i = 0; i < n; i++) + { + if(left == sum - v[i]) + { + cout<