C program to print mirrored half diamond star pattern

Write a C program to print the mirrored half diamond star(*) pattern using for loop. How to print mirrored half diamond star pattern structure using for loop in C programming. Logic to print mirrored half diamond star pattern in C program.

Example

Input

Input rows: 5

Output

Required knowledge

Basic C programming, For loop

Read more - Program to print half diamond star pattern

Logic to print mirrored half diamond star pattern

Here to print this pattern I am going to bisect the pattern to make the task easy.

Now, if you have done with previous patterns you will find that the first half is the mirrored right triangle star pattern and the second half is the inverted mirrored right triangle star pattern. Hence, in-order to get the final pattern we need to write the codes of both the pattern one by one.

Program to print mirrored half diamond star pattern

/**
 * C program to print mirrored half diamond star pattern
 */

#include <stdio.h>

int main()
{
    int i, j, n;

    // Input number of columns to print from user
    printf("Enter number of columns : ");
    scanf("%d", &n);

    // Print upper half part of the pattern
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(j=1; j<=i; j++)
        {
            printf("*");
        }
        printf("\n");
    }
    
    // Print lower half part of the pattern
    for(i=n; i>=1; i--)
    {
        for(j=i; j<=n; j++)
        {
            printf(" ");
        }
        for(j=1; j<i; j++)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

Output

Enter number of columns : 5
    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>