Welcome to Westonci.ca, where finding answers to your questions is made simple by our community of experts. Get accurate and detailed answers to your questions from a dedicated community of experts on our Q&A platform. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

Write a function solution that, given an array A consisting of N integers, returns the number of fragements of A whose sum equals 0 (that is, pairs (p,q) such that P

Sagot :

Answer:

#include <iostream>

using namespace std;

void fragment(int arr[], int n){

   for (int i = 0; i < n; i++){

       for (int x = 0; x < n; x++){

           if (x != i && arr[i] + arr[x] == 0){

               cout<< arr[i] << " , " << arr[x];

           }

       }

   }

}

int main(){

   int n = 7;

   int myArr = {1, 2, -1, -2, 0, 0, 3};

   fragment(myArr, n);

}

Explanation:

The C++ source code defines an array called "myArr" in the main program and its array size n. The void function "fragment" prints out the pairs of the array whose sum equates to zero.

We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.