Fill a 2-D Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shahzadali007
    New Member
    • Feb 2007
    • 3

    Fill a 2-D Box

    Given a 2^n by 2^n checkerboard with any one square deleted, it is possible to cover this board with L-shaped pieces.

    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 ♣.


    Code:
    #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 &
      }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    which operating system and compiler are you using?

    Comment

    • shahzadali007
      New Member
      • Feb 2007
      • 3

      #3
      i m using Turbo C 3.0 uner DOS environment

      Comment

      • shahzadali007
        New Member
        • Feb 2007
        • 3

        #4
        I think there is no body brave enough to solve my problem.Where is the community going??

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          I think we've interpreted your question as a homework assignment, and without you asking us for help or clarification, we're not sure what you want.

          Comment

          Working...