2-dim array function

#include <cmath> #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int N = 5; void test(double **A, int k) { for (int i = 0; i < k; i++) { for (int j = 0; j < N + 1; j++) { A[i][j] = 0; A[j][i] = 0; } } for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { if (i == j) A[i][j] = 1; } } } int main() { double ** A = new double *[N + 1]; for (int i = 0; i < N+1; i++) A[i] = new double[N+1]; for (int i = 0; i < N+1; i++) { for (int j = 0; j < N+1; j++) { A[i][j] = i + j; cout << A[i][j] << " "; } cout << endl; } cout << endl; test(A, 3); for (int i = 0; i < N+1; i++) { for (int j = 0; j < N+1; j++) { cout << A[i][j] << " "; } cout << endl; } system("pause"); return 0; }
Изменяет аргумент

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.