October 10, 2013

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.

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

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


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


    How to Write this program to Print Star Pattern in Java

    ReplyDelete
  8. 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
  9. 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
  10. This comment has been removed by the author.

    ReplyDelete
  11. Thank you very much! Really helpful for programmers c programming assignment help

    ReplyDelete

C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...