Thread: hollow rectangle

  1. #1
    Unregistered
    Guest

    hollow rectangle

    I need a simple algorithm with nothing complicated, no pointers, arrays ect.

    I need to draw a HOLLOW rectangle of any given dimensions..

    NOT

    ****
    ****
    ****

    No "*" inside, only the borders.

    Please somebody tell me the right way to do it.

  2. #2
    Unregistered
    Guest
    how about this?
    printf(***);
    printf(* *);
    printf(***);

  3. #3
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    Try with loops...............I'd recomend for
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  4. #4
    Unregistered
    Guest
    I need an algorithm

    The users enters the dimesnion, say:

    height = 3
    width = 4

    output:

    ****
    *``*
    ****

    but ofcourse the ` arent there. only put it in so that the output would look right.

    Does anbody know an algorithm for a hollow rectangle

    thanks

  5. #5
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    are you the same person who asked this in the game board..

    Code:
     
    do
    {
     cin>>ans;
     ans=toupper(ans);
    }
    while(ans!='Y' && ans!='N');
    
    if(ans=='Y')
    {
     dont_cross_post();
     gameprog_board();
    }
    else
     gameprog_board();
    -

  6. #6
    Unregistered
    Guest
    The horizontal will be your inner loop and the vertical will be your outer loop. The number of blanks will be two less than each dimension. Play with it a bit. We don't want to do all of your homework.

  7. #7
    Registered User That1Guy's Avatar
    Join Date
    Feb 2002
    Posts
    5

    hollow rectangle - my solution

    OK, I'll bite this once but I'm a total noob myself and can't testify to the quality of my solution. It works, but it's not pretty.

    -That1Guy

    Code:
    #include <stdio.h>
    
    int main(void)
    {
            int i;  
            int j;  
    
            int numRows = 15;
            int numCols = 15;
    
            int rowCount = 0;
            int colCount = 0;
    
            for(i = 0; i < numRows; i++)
            {       
                    if(rowCount == 0 || rowCount == (numRows - 1))
                    {       
                            rowCount++;
    
                            for(j = 0; j < numCols; j++)
                                    printf("*");
                            printf("\n");
                    }       
                    else    
                    {       
                            rowCount++;
    
                            for(j = 0; j < numCols; j++)
                            {       
                                    if(colCount == 0 || colCount == (numCols - 1))
                                    {       
                                            colCount++;
                                            printf("*");
                                    }       
                                    else    
                                    {       
                                            colCount++;
                                            printf(" ");
                                    }       
                            }       
    
                            printf("\n");
                            colCount = 0;
                    }       
            }       
            
            return(0);
    }

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    This question is asked often enough that a board search will work wonders. I know that quzah and I gave solutions to this problem not a week ago.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rectangle class
    By blackant in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 08:33 AM
  2. segmetation fault (reading and writing file in c)
    By tasosa in forum C Programming
    Replies: 5
    Last Post: 04-13-2009, 06:04 AM
  3. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 02:33 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Collision detection algorithm
    By Hannwaas in forum Game Programming
    Replies: 5
    Last Post: 11-30-2001, 01:27 PM