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

Here are solutions for finding three contiguous 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++) {
int sum = arr[i] + arr[i + 1] + arr[i + 2];
if (sum == 0) {
printf("Triplet found: %d, %d, %dn", arr[i], arr[i + 1], arr[i + 2]);
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>

void findElements(int arr[], int n) {
for (int i = 0; i < n - 2; i++) {
int sum = arr[i] + arr[i + 1] + arr[i + 2];
if (sum == 0) {
std::cout << "Triplet found: " << arr[i] << ", " << arr[i + 1] << ", " << arr[i + 2] << std::endl;
return;
}
}
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):
sum = arr[i] + arr[i + 1] + arr[i + 2]
if sum == 0:
print("Triplet found:", arr[i], ",", arr[i + 1], ",", arr[i + 2])
return
print("No triplet found.")

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

```
1. Solution in Java:
```class Main {
static void findElements(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 2; i++) {
int sum = arr[i] + arr[i + 1] + arr[i + 2];
if (sum == 0) {
System.out.println("Triplet found: " + arr[i] + ", " + arr[i + 1] + ", " + arr[i + 2]);
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 and check the sum of each group of three contiguous elements. If the sum is zero, the triplet is found and printed; otherwise, the function continues to search. The C and C++ solutions use a loop, while the Python and Java solutions utilize a for loop to iterate over the array.