top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to print hollow square of stars(4*4) in a matrix form?

+1 vote
237 views
How to print hollow square of stars(4*4) in a matrix form?
posted Oct 4, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Code for hollow square:

int main()
{
    int N = 4;
    int r=4, c=4;

    for (int i = 1; i <= r; ++i)
    {
        for (int j = 1; j <= c; ++j)
        {
            if(j%4 == 0 || j%4 == 1)
                printf("*");

            else if(i%4 == 0 || i%4 == 1)
                printf("*");

            else
                printf(" ");
        }
        printf("\n");
    }
}
answer Oct 5, 2015 by Manikandan J
Similar Questions
+1 vote

How to create a c program to print a alphabet in the form of stars for ex.
A should be printed something like

   *
  * *
 *****
*     *

Do we have any standard algo???

–1 vote

Given an ODD number, print diamond pattern of stars recursively.

Example
Input: n = 5,

Output:

  *
 ***
*****
 ***
  *
...