Вопрос задан 17.06.2023 в 02:43. Предмет Информатика. Спрашивает Нусратова Карина.

C++ Вычитание из значения каждого элемента матрицы номера строки данного элемента. Разработать

бестиповую функцию для выполнения над матрицей размером mхm операций в соответствии с вариантом. На печать вывести исходную и преобразованную матрицы. Примечание: Исходную матрицу сформировать, используя функцию Form_matrix c датчиком псевдослучайных чисел rand(). в чем ошибка? без"**" #include #include #include #include using namespace std; const int m=5; int Form_matrix(int A[][m], int m) { int j = 0, k, l; for (k = 0; k < m; k++) { for (l = 0; l < m; l++) { A[k][l] = rand() % 199 - 99; cout << setw(4) << A[k][l]; if (A[k][l] > 0) j = A[k][l]; } cout << endl; } return j; } int main() { int j, k, l, m, min; srand(time(nullptr)); while (true) { cout << "m: "; int a[m]; for (k = 0; k < m; k++) a[k] = a[m]; j = Form_matrix(a, m); min = j; if (j) { for (k = 0; k < m; k++) for (l = 0; l < m; l++) if (a[k][l] > 0 && a[k][l] < min) min = a[k][l]; cout << "min = " << min << endl; } else cout << "no positive elements" << endl; for (k = 0; k < m; k++) delete [] a[k]; } }
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Сенють Настя.

Ответ:

(((((ия здела на фоте )))))



0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

It looks like you've provided a piece of C++ code related to matrix operations. However, the code seems to have some errors and is not formatted properly. Let's break down the code and address the issues step by step.

Understanding the Task

Before diving into the code, it's important to understand the task at hand. The task is to perform a subtraction operation on a matrix by subtracting the row number of each element from its value. Additionally, the task requires implementing a non-typed function to perform these operations on a matrix of size m x m, and then printing both the original and transformed matrices.

Code Analysis and Corrections

Now, let's analyze the code you've provided and make the necessary corrections.

```cpp #include #include #include #include

using namespace std;

const int m = 5;

// Function to form the matrix using pseudo-random numbers void Form_matrix(int A[][m], int m) { for (int k = 0; k < m; k++) { for (int l = 0; l < m; l++) { A[k][l] = rand() % 199 - 99; cout << setw(4) << A[k][l]; } cout << endl; } }

// Main function to perform matrix operations int main() { int A[m][m]; srand(time(nullptr));

cout << "Original Matrix:" << endl; Form_matrix(A, m);

cout << "\nTransformed Matrix:" << endl; for (int k = 0; k < m; k++) { for (int l = 0; l < m; l++) { A[k][l] -= k; cout << setw(4) << A[k][l]; } cout << endl; }

return 0; } ```

Explanation of Corrections

1. Header Inclusion: I've corrected the header inclusions to match the standard C++ library headers. 2. Function Definition: Changed the return type of `Form_matrix` to `void` as it's responsible for populating the matrix and not returning any value. 3. Main Function: Redefined the main function to initialize the matrix, call the `Form_matrix` function to populate the original matrix, perform the subtraction operation on the elements based on the row number, and print the transformed matrix.

The corrected code should now fulfill the requirements of the given task. If you have any more specific questions or need further assistance, feel free to ask!

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос