C program to print the hollow stars square

Here is the code for the C program to print the star formation of a hollow square. The program will input an integer value from the user and print the hollow star formations.
Here is the code.

#include “stdio.h”
int main()
{
int num,i,j;
printf("Please enter a number to print the hollow star formation \n");
scanf("%d", &num);
for(i=0;i<num;i++)
{
for(j=0;j<num;j++)
{
if(i==0 || i==num-1)
{
printf("*");
}
else if(j==0 || j==num-1)
{
printf("*");
}
else
{
printf(" "); // space is printed ..
}
}
printf("\n");
}
return 0;
}


























Here is the sample output.
star

As can be seen in the output above, for the user input, the hollow star square will be formed. The key to understand the logic of the code is as follows.
The outerloop controls the number of  lines and inner loop controls the number of stars.

Reactions:

11 comments:

  1. Thank you soo much!!
    You've helped me a lot!! >3<
    haha..

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thank you so much! Really helpful for newbie programmers up to this day :)

    ReplyDelete
  4. i want to code a rectangle of stars within a rectangle of stars can anybody help me thanks?

    ReplyDelete
  5. Please help me in coding of diamond with hollow center and many stars around the center

    ReplyDelete
  6. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  7. Java jobs are becoming more plentiful as the use of this software is more and more common online. Those skilled in java applications are in demand now by telecommuting companies. These jobs allow you to work from home with java software. See more assignment programming

    ReplyDelete

  8. I want these code in Java Can you give me code ?


    #
    ###
    #####
    ##
    #


    How to Write this program to Print Star Pattern in Java

    ReplyDelete
  9. Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.

    ReplyDelete
  10. In Chau Long We are proud to bring our customers the products of printing paper bags, printing paper boxes, printing catalogs, printing directories, printing leaflets, high quality printing leaflets, reasonable prices and Meet all requirements for the customer's process set.

    in ấn tại bắc ninh

    Công ty in offset tại Bắc Ninh

    in offset hà nội

    in offset giá rẻ hà nội

    ReplyDelete