Skip to content

Instantly share code, notes, and snippets.

@JohannesMP
Created July 20, 2012 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesMP/39f795b6c56e838bada2 to your computer and use it in GitHub Desktop.
Save JohannesMP/39f795b6c56e838bada2 to your computer and use it in GitHub Desktop.
#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[rows];
}
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