top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+1 vote
43 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 Google+ Share Button LinkedIn Share Button Multiple Social 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:

  *
 ***
*****
 ***
  *
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...