#include <iostream> #include <math.h> #include <iomanip> using namespace std; int **ptrarray, N; int min = 0; int Function_Min_elem( int min, int N, int **ptrarray) { for (int count_row = 0; count_row < N + 15; count_row++) { for (int count_column = 0; count_column < N + 15; count_column++) { if (min > ptrarray[count_row][count_column]) min = ptrarray[count_row][count_column]; } // НахоТдСниС мниимального элСмСнта; } return min; } void Function_sum_elem1(int N, int sum) { for (int count_row = 0; count_row < N + 15; count_row++) { for (int count_column = 0; count_column < N + 15; count_column++) sum = ptrarray[count_row][count_column] + sum; //Π‘ΡƒΠΌΠΌΠ° элСмСнтов массива } cout << " " << endl; cout << " Π‘ΡƒΠΌΠΌΠ° элСмСнтов массива = " << sum << endl; } int Create_Massiv(int **ptrarray, int N ) { for (int counter = 0; counter < N + 15; counter++) ptrarray[counter] = new int[N + 15]; //создаСм массив for (int count_row = 0; count_row < N + 15; count_row++) { for (int count_column = 0; count_column < N + 15; count_column++) { ptrarray[count_row][count_column] = rand() % ((15 + N) * 2 + 1) - 15 - N; // ЗаполняСм массив } } return **ptrarray; } void Print(int **ptrarray, int N) { cout << setw(5); for (int count_row = 0; count_row < N + 15; count_row++) { for (int count_column = 0; count_column < N + 15; count_column++) cout << ptrarray[count_row][count_column] << setw(5); cout << endl; } // Π’Ρ‹Π²ΠΎΠ΄ Π΅Π»Π΅ΠΌΠ΅Π½Ρ‚ΠΎΠ² массива cout << endl; } int Vvod() { cout << "Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Ρ‚Ρ€ΡƒΠ°Π»ΡŒΠ½ΠΎΠ΅ число N" << endl; cin >> N; return N; } int main() { setlocale(LC_ALL, "Russian"); system("mode con cols=200 lines=200"); int sum = 0, sum_el_mat = 0, sum_el_mat2 = 0; Vvod(); if (N >-12) // ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ { cout << "" << endl; ptrarray = new int*[N + 15]; /// Create_Massiv(ptrarray,N); Print(ptrarray, N); Function_sum_elem1(N,sum); Function_Min_elem(min, N, ptrarray); cout << " НаимСньший Π΅Π»Π΅ΠΌΠ΅Π½Ρ‚ = " << min << endl; int Mmin = abs(min); cout << " НаимСньший Π΅Π»Π΅ΠΌΠ΅Π½Ρ‚ gj vjl = " << Mmin << endl; // ΠΠ±ΡΠΎΠ»ΡŽΡ‚Π½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ min элСмСнта 

Closed due to the fact that off-topic participants αλΡχολυτ , Kromster , Denis , cheops , aleksandr barakin 3 Nov '16 at 7:25 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • β€œQuestions asking for help with debugging (β€œ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, Denis, cheops, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What is it? It is not even collected after being brought into the human species. - PinkTux

1 answer 1

What is the function Function_Min_elem( int min, int N, int **ptrarray) min in the Function_Min_elem( int min, int N, int **ptrarray) parameters?

  1. In Function_Min_elem work goes with the local variable min , and when the Function_Min_elem called, the assignment to the global variable min nowhere to be found.

  2. Even when you call Function_Min_elem(min, N, ptrarray) , 0 comes in, and in the array all elements can be> 0, and you get 0 as the minimum.

Option 1. Call Function_Min_elem with the first element of the array and assign the result to the global min

 int main() { ... if (N >-12) { ... min = ptrarray[0][0]; //ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅ΠΌ min min = Function_Min_elem(min, N, ptrarray); //записываСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Π² min ... } } 

Option 2 .. Inside the function, assign the min element the value of the first element of the array. In this case, it is better to remove the argument from the min parameters altogether, it will be superfluous there. And do not forget to write the result in the global variable min = Function_Min_elem(min, N, ptrarray);

 int Function_Min_elem( int min, int N, int **ptrarray) { min = ptrarray[0][0]; //Как Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ здСсь min элСмСнту ΠΏΡ€ΠΈΡΠ²Π°ΠΈΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ элСмСнт массива for (int count_row = 0; count_row < N + 15; count_row++) { for (int count_column = 0; count_column < N + 15; count_column++) { if (min > ptrarray[count_row][count_column]) min = ptrarray[count_row][count_column]; } } return min; }