Error in the code on line 29:
Access violation when reading at ...
#include<iostream> using namespace std; void print(double **matr, int size) { cout << endl << endl; for (int i = 0;i < size;i++) { for (int j = 0; j < size; j++) { cout << matr[i][j] << " | "; } cout << endl; } } double Determinant(double **a,int size) { double det = 0; if (size == 1) { det = a[0][0]; } if (size == 2) { det = a[0][0] * a[1][1] - a[0][1] * a[1][0]; } if (size > 2) { double **c = new double*[size]; for (int k = size - 1;k <= size;k++) { for (int i = k + 1;i <= size;i++) { c[i][k] = a[i][k] / a[k][k]; for (int j = k + 1;j <= size;j++) { a[i][j] = a[i][j] - (c[i][k] * a[k][j]); } } } } for (int i = 0;i < size;i++) det *= a[i][i]; return det; } int main() { setlocale(LC_ALL, "Russian"); int size; cout << "Введите количество неизвестных: "; cin >> size; double **Matx = new double *[size]; for (int i = 0;i < size;i++) { Matx[i] = new double[size]; } for (int i = 0;i < size;i++) { for (int j = 0;j < size;j++) { cin >> Matx[i][j]; } } print(Matx, size); cout << "Детерминант: " << Determinant(Matx, size) << endl; //Удаление for (int i = 0; i < size; i++) { delete[] Matx[i]; // Удаляем каждый элемент } delete[] Matx; system("pause"); return 0; } What is the cause of the error?
In function 'int main()': error: 'size' was not declared in this scope: double **Matx = new double *[size];- PinkTuxk <= sizeconditions and automatically go beyond the array. - KoVadim 4:39 pmk < size, it will not go into the cycle at all. - Suhoy571