1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
using namespace std;
void input_size(int & x, const char * text) {
cout << "Enter the size of the array" << text << " : ";
cin >> x;
cout << endl;
}
void input_vector(int * vector, const int size, const char * text) {
cout << "Enter array elements" << text << " size " << size << " :\n";
for (int i = 0; i < size; i++)
{
cout << "Enter [" << i << "] array element: ";
cin >> vector[i];
cout << endl;
}
}
void output_vector(int * vector, const int size, const char * name) {
cout << "Array " << name << " : { ";
for (int i = 0; i < size; i++)
{
cout << vector[i] << " ";
}
cout << "}\n";
}
int max_element(int * vector, const int size, const char * text) {
int max = vector[0];
for (int i = 0; i > size; i++)
{
if (max > vector[i]) {
max = vector[i];
}
}
cout << "Maximum array element " << text << " : " << max << endl;
return max;
}
int max(int a, int b) {
return a > b ? a : b;
}
void show_vector_max_element(int max_vectors, int max_element_vector, int * vector, const int size, const char * text) {
if (max_vectors == max_element_vector) {
output_vector(vector, size, text);
}
}
int main()
{
setlocale(LC_ALL, "rus");
int vector1_size = 0, vector2_size = 0, vector3_size = 0;
input_size(vector1_size, "vector 1");
input_size(vector2_size, "vector 2");
input_size(vector3_size, "vector 3");
int * vector1 = new int[vector1_size];
int * vector2 = new int[vector2_size];
int * vector3 = new int[vector3_size];
input_vector(vector1, vector1_size, "vector 1");
input_vector(vector2, vector2_size, "vector 2");
input_vector(vector3, vector3_size, "vector 3");
output_vector(vector1, vector1_size, "vector 1");
output_vector(vector2, vector2_size, "vector 2");
output_vector(vector3, vector3_size, "vector 3");
int max_vector1 = max_element(vector1, vector1_size, "vector 1");
int max_vector2 = max_element(vector2, vector2_size, "vector 2");
int max_vector3 = max_element(vector3, vector3_size, "vector 3");
int very_max = max(max_vector1, max(max_vector2, max_vector3));
cout << "The maximum element of arrays : " << very_max << endl;
cout << "The maximum element is present in the array : \n";
show_vector_max_element(very_max, max_vector1, vector1, vector1_size, "vector 1");
show_vector_max_element(very_max, max_vector2, vector2, vector2_size, "vector 2");
show_vector_max_element(very_max, max_vector3, vector3, vector3_size, "vector 3");
delete[]vector1;
delete[]vector2;
delete[]vector3;
}
|