#include <iostream> #include <cstring> #include <cstdlib> //Prototypes for all functions int **dimension(int, int); void calc_result_iterative(int, int, int); void calc_result_recursion(int, int, int, int, int); using namespace std; int main(){ int rows, cols, n, row, col; cout << "How many rows and columns would you like to use? "<<endl; cin >> n; int **dim = dimension(n, n); calc_result_iterative(dim, rows, cols); //calc_result_reciursion(dim, rows, cols, row, col); return 0; } void calc_result_iterative(int **dim, int rows, int cols){ for(int row = 0; row < rows; row++ ){ for(int col = 0; col < cols; col++){ cout << dim[row][col] << endl << endl <<endl; } } } void calc_result_recursion(int **dim, int rows, int cols, int row, int col){ if(col == cols && row == rows-1) return; if(col == cols){ col == 0; col++; cout<< endl<< endl<<endl; } cout << dim[row][col] << " "; calc_result_recursion(dim, rows, cols, row+1, col); } int **dimension(int rows, int cols){ int **dim = new int*[rows]; for(int i = 0; i < cols; i++) dim[i] = new int[cols]; return dim; } |
|
|