The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Hollow Diamond Square Star Pattern In C

Why Star Pattern

In most of the MNC interview questions such as in ZOHO interview questions, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, we come across star pattern questions with a probability of 1:5. We provide you a most commonly asked hollow diamond square star pattern question for your interview preparation using C programming.

Lets code a C program to print hollow diamond square star pattern to have some fun

Hollow Diamond Square Star Pattern

We challenge you, the programmer to do the hollow diamond square star pattern using C programming

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

C Programming logic

step 1: Split this program into 2 parts.

step 2: part one contains.

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

step 3: part two contains.

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

step 4: From the above star Pattern, we can easily identify, this c program contains 3 for loop.

  • for loop represents every new line.
  • for loop for displaying 0.
  • for loop for displaying *.

step 5: Finally, combine these two star Pattern

Facts

  • C program is not capable of transferring its control from line 2 to line 1.
  • Thus the programmer need to complete the line 1 before executing the line 2.

Hollow Diamond Square Star Pattern - Part 1

hollow-diamond-square-star-pattern-1
**********
****  ****
***    ***
**      **
*        *
hollow-diamond-square-star-pattern-1.c
#include<stdio.h>
int main()
{
int i, j, k, m, a = 1;
for(i = 5;i > 0;i--)
{
for(j = i;j > 0;j--)
{
printf("*");
}
for(k = 1;k < a;k++)
{
printf(" ");
}
a = a + 2;
for(m = i;m > 0;m--)
{
printf("*");
}
printf("\n");
}
return 0;
}
**********
****  ****
***    ***
**      **
*        *

Hollow Diamond Square Star Pattern - Part 2

hollow-diamond-square-star-pattern-2
**      **
***    ***
****  ****
**********
hollow-diamond-square-star-pattern-2.c
#include<stdio.h>
int main()
{
int i, j, k, n, m = 0;
for(i = 1;i <= 4;i++)
{
for(j = 0;j <= i;j++)
{
printf("*");
}
for(k = 6;k > m;k--)
{
printf(" ");
}
m = m + 2;
for(n=0;n <= i;n++)
{
printf("*");
}
printf("\n");
}
return 0;
}
**      **
***    ***
****  ****
**********

Hollow Diamond Square Star Pattern

hollow-diamond-square-star-pattern
**********
****  ****
***    ***
**      **
*        *
**      **
***    ***
****  ****
**********
hollow-diamond-square-star-pattern.c
#include<stdio.h>
int main()
{
int i, j, k, m, a = 1,b = 0;
for(i = 5;i > 0;i--)
{
for(j = i;j > 0;j--)
{
printf("*");
}
for(k = 1;k < a;k++)
{
printf(" ");
}
a = a + 2;
for(m = i;m > 0;m--)
{
printf("*");
}
printf("\n");
}
for(i = 1;i <= 4;i++)
{
for(j = 0;j <= i;j++)
{
printf("*");
}
for(k = 6;k > b;k--)
{
printf(" ");
}
b = b + 2;
for(m = 0;m <= i;m++)
{
printf("*");
}
printf("\n");
}
return 0;
}
**********
****  ****
***    ***
**      **
*        *
**      **
***    ***
****  ****
**********

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report