#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
- What is it? It is not even collected after being brought into the human species. - PinkTux
1 answer
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?
In
Function_Min_elemwork goes with the local variablemin, and when theFunction_Min_elemcalled, the assignment to the global variableminnowhere to be found.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; }