# Find 3 elements of an array with sum equals zero with example in c,c++,python and java

Here are solutions for finding three elements in an array whose sum equals zero in C, C++, Python, and Java:

1. Solution in C:
```#include <stdio.h>

void findElements(int arr[], int n) {
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
if (arr[i] + arr[j] + arr[k] == 0) {
printf("Triplet found: %d, %d, %dn", arr[i], arr[j], arr[k]);
return;
}
}
}
}
printf("No triplet found.n");
}

int main() {
int arr[] = {2, -5, 7, -3, 1, -1, 0};
int size = sizeof(arr) / sizeof(arr[0]);

findElements(arr, size);

return 0;
}

```
1. Solution in C++:
```#include <iostream>
#include <unordered_set>

void findElements(int arr[], int n) {
for (int i = 0; i < n - 2; i++) {
std::unordered_set<int> elements;

for (int j = i + 1; j < n; j++) {
int complement = -(arr[i] + arr[j]);
if (elements.count(complement)) {
std::cout << "Triplet found: " << arr[i] << ", " << arr[j] << ", " << complement << std::endl;
return;
}
elements.insert(arr[j]);
}
}
std::cout << "No triplet found." << std::endl;
}

int main() {
int arr[] = {2, -5, 7, -3, 1, -1, 0};
int size = sizeof(arr) / sizeof(arr[0]);

findElements(arr, size);

return 0;
}

```
1. Solution in Python:
```def find_elements(arr):
n = len(arr)
for i in range(n - 2):
elements = set()

for j in range(i + 1, n):
complement = -(arr[i] + arr[j])
if complement in elements:
print("Triplet found:", arr[i], ",", arr[j], ",", complement)
return

print("No triplet found.")

arr = [2, -5, 7, -3, 1, -1, 0]
find_elements(arr)

```
1. Solution in Java:
```import java.util.HashSet;

class Main {
static void findElements(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 2; i++) {
HashSet<Integer> elements = new HashSet<>();

for (int j = i + 1; j < n; j++) {
int complement = -(arr[i] + arr[j]);
if (elements.contains(complement)) {
System.out.println("Triplet found: " + arr[i] + ", " + arr[j] + ", " + complement);
return;
}
}
}
System.out.println("No triplet found.");
}

public static void main(String[] args) {
int[] arr = {2, -5, 7, -3, 1, -1, 0};
findElements(arr);
}
}

```

These solutions iterate over the array using nested loops and use different techniques to find three elements whose sum is zero. The C and C++ solutions use three nested loops and an unordered set, while the Python and Java solutions also use two loops and a set or HashSet to store the elements and check for the existence of the complement.