A
A
Alexander2020-11-26 19:23:56
Mathematics
Alexander, 2020-11-26 19:23:56

How to create pairs of array elements so that they match a given condition?

Task: write a program that receives a set (array) with n>30 elements as input and sets a relation on it with given properties (reflexivity, symmetry, transitivity).
The number of pairs of elements of the initial set that belong to the relation must be at least n^3/2.
Here you can understand the relationship properties: I


have the code, but I do not know how to select pairs of elements that match the condition:

#include <iostream>
using namespace std;

int main()
{
  int a, b, c; // parameters for input
  const int size = 40; // suppose: size = 40 (40>30)
  int ARR[size];

  for (int i = 0; i < size; i++)
  {
    cin >> ARR[i];
  }

  cout << "\nChoose the properties of the relation: " << endl;
  cout << "1 - reflective" << endl
    << "2 - not reflective" << endl
    << "3 - symmetric" << endl
    << "4 - not symmetric" << endl
    << "5 - transitive" << endl
    << "6 - not transitive" << endl;
  cin >> a >> b >> c;

  cout << "Let's suppose that the operation is '>=' ";

  if (a == 1 && b == 3 && c == 5) // reflective, symmetric, transitive
  {
    for (int i = 0; i < size - 1; i++)
    {
      if (ARR[i] == ARR[i] && ARR[i] >= ARR[i + 1] >= ARR[i] && ARR[i] >= ARR[i + 1] >= ARR[i + 2])
      {
        
      }
      
    }
  }

}

The output should be in the form (a, b) - all possible pairs of elements that match the condition.
Help me sort this out, please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question