For example, a 4x4 checkerboard coudl be covered like this.
w w u u
w t t u
j ♣ t e
j j e e
you shall represent the checkerboard ising a dynamically allocated 2-D array. The user shall give you the value of "n" for the 2^nx2^n matrix.
The prototype of the recursive function that you'll write is given below:
void LRec(int row, int col, int** array, int size, int ptx, int pty);
ptx and pty indicate the row and column indices of the space in array that shall remain filled with ♣.
Expand|Select|Wrap|Line Numbers
- #include <graphics.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <iostream.h>
- #include <string.h>
- #include <math.h>
- #include <process.h >
- void LRec(int row, int col, int** array, int size, int ptx, int pty);
- int main(void)
- {
- const int TWO=2;
- int n;
- clrscr();
- cout<<"Enter the value of n for a 2^n x 2^n matrix :";
- cin>>n;
- if (n<0)
- {
- cout<<"sorry!";
- return 1;
- }
- int power2=(int)pow(TWO,n);
- int power2=pow(TWO,n);
- int** LArray = new int*[power2];
- int i,j;
- for (i=0; i<power2; i++)
- LArray = new int[power2];
- for (i=0; i<power2; i++)
- for (j=0; j<power2; j++)
- LArray[j] = 5;
- int ptx, pty;
- srand ( (unsigned)time(NULL));
- ptx = rand()%(power2);
- pty = rand()%(power2);
- cout <<"ptx= "<<ptx<<" pty = "<<pty<<endl;
- LRec(0,0, LArray, power2, ptx, pty);
- cout<<endl;
- for (i=0; i<power2; i++)
- {
- for (j=0; j<power2; j++)
- cout<<(char)LArray[j]<<" ";
- cout<<endl<<endl;
- }
- getch();
- return 0;
- }
- void LRec(int row, int col, int** array, int size, int ptx, int pty)
- {
- //Write your code here &
- }