-
-
Save JohannesMP/b650708f132b980cab24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int **pparray_create(int cols, int rows) | |
{ | |
int **pparray = new int*[rows]; | |
for(int i = 0; i < rows; i++) | |
{ | |
pparray[i] = new int[cols]; | |
for (int j = 0; j < cols; j++) | |
{ | |
pparray[i][j] = 0; | |
} | |
} | |
return pparray; | |
} | |
void pparray_delete(int **pparray, int cols, int rows) | |
{ | |
for(int i = 0; i < rows; i ++) | |
{ | |
delete [] pparray[i]; | |
} | |
delete pparray; | |
} | |
void pparray_multiplication_table(int **pparray, int cols, int rows) | |
{ | |
for(int i = 0; i < rows; i++) | |
{ | |
for (int j = 0; j < cols; j++) | |
{ | |
pparray[i][j] = (i+1) * (j+1); | |
} | |
} | |
} | |
void pparray_print(int **pparray, int cols, int rows) | |
{ | |
for(int i = 0; i < rows; i++) | |
{ | |
for (int j = 0; j < cols; j++) | |
{ | |
cout << "|" << pparray[i][j] << "\t"; | |
} | |
cout << "| \n"; | |
} | |
} | |
int main() | |
{ | |
int cols = 2; | |
int rows = 3; | |
int **my_array; | |
cout << "\n empty array, cols: " << cols << ", rows: " << rows << " \n"; | |
my_array = pparray_create(cols,rows); | |
pparray_print(my_array, cols, rows); | |
cout << "\n multiplication table: \n"; | |
pparray_multiplication_table(my_array, cols, rows); | |
pparray_print(my_array, cols, rows); | |
cout << "\n -deleting array- \n"; | |
pparray_delete(my_array, cols, rows); | |
cols = 5; | |
rows = 7; | |
my_array = pparray_create(cols,rows); | |
cout << "\n empty array, cols: " << cols << ", rows: " << rows << " \n"; | |
pparray_print(my_array, cols, rows); | |
cout << "\n multiplication table: \n"; | |
pparray_multiplication_table(my_array, cols, rows); | |
pparray_print(my_array, cols, rows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment