0% found this document useful (0 votes)
157 views2 pages

Hollow Diamond Pattern

The document discusses printing a hollow diamond star pattern in C programming. It explains that the pattern can be divided into two symmetrical halves, with inverted right triangles of stars on the edges and a number of spaces in the middle that increases by 2 for each row. The document provides sample input/output and the C code to generate this pattern using for loops, with one loop to print the upper half and another for the lower half.

Uploaded by

Shanmuk_Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views2 pages

Hollow Diamond Pattern

The document discusses printing a hollow diamond star pattern in C programming. It explains that the pattern can be divided into two symmetrical halves, with inverted right triangles of stars on the edges and a number of spaces in the middle that increases by 2 for each row. The document provides sample input/output and the C code to generate this pattern using for loops, with one loop to print the upper half and another for the lower half.

Uploaded by

Shanmuk_Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write a C program to print hollow diamond star pattern series of n rows using for

loop. How to print hollow diamond star pattern structure in C program. Logic to
print hollow diamond star pattern in C programming.

Example

Input

Input N: 5
Output

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

Required knowledge
Basic C programming, For loop, Nested loop

Must know - Program to print diamond star pattern

Logic to print hollow diamond star pattern


The pattern seems to be one of the complex pattern to think. To make it easier, let
us bisect in two halves.

**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
Here in the upper part of the pattern, trailing and leading stars are inverted
right triangle pattern that can be easily printed. Each row contains 2*rownumber -
2 spaces.
Moving on to the second half, if you look at the trailing and leading stars you
will find that both of them are right triangle star pattern and total number of
spaces per row is 2*rownumber - 2.

Program to print hollow diamond star pattern


/**
* C program to print hollow diamond star pattern
*/

#include <stdio.h>

int main()
{
int i, j, n;
printf("Enter value of n : ");
scanf("%d", &n);

// Loop to print upper half of the pattern


for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf("*");
}

for(j=1; j<=(2*i-2); j++)


{
printf(" ");
}

for(j=i; j<=n; j++)


{
printf("*");
}

printf("\n");
}

// Loop to print lower half of the pattern


for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("*");
}

for(j=(2*i-2); j<(2*n-2); j++)


{
printf(" ");
}

for(j=1; j<=i; j++)


{
printf("*");
}

printf("\n");
}

return 0;
}
Output
Enter value of n : 5
**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy