Pattern 8: Diamond or Rhombus pattern program in C

Spread the love

Introduction:

We are going to discuss about the Rhombus Pattern program in this article, Sometimes we also call this as Diamond pattern. We are going to use C for loops to create the pattern.

Write a C Program to print below pattern ( Rhombus Pattern Program) :

Here is the Expected Output, When user specified the input as 5. 

*
   * *
  * * *
 * * * *
* * * * *
* * * * * *
* * * * *
 * * * *
  * * *
   * * 
*
 
or 
 
Rhombus-pattern-program-in-c
 
Note: At the middle row we have (n+1) stars. i.e 6 stars in this case.

Rhombus (Diamond) Pattern Explanation :

This is one the series of pattern programs in C. This program is very similar to my previous pattern program “Pyramid Star pattern program in C Language“.

Here I am using only two for loops to create above pattern. First for loop is responsible for the number of rows. so it always starts with -n. The inner loop is for columns. I am using small logic(using variable ‘k’) to accomplish this pattern with only two loops.

Rhombus Pattern Program:

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,j,k,n;
  5.  
  6. printf(“Enter the Value for n : “);
  7. scanf(“%d”,&n);
  8.  
  9. for(i=-n; i<=n; i++) // Note that ‘i’ is starting from -n (negative n)
  10. {
  11.         k=i;
  12. if(k<0)
  13.             k= k*-1;
  14.  
  15. for(j=0;j<=n;j++)
  16. {
  17. if(k<=j)
  18. printf(“* “);
  19. else
  20. printf(” “);
  21. }
  22. printf(“\n);
  23. }
  24. return 0;
  25. }

Output:

Rhombus-Pattern-Program-in-c-programming

 

Similar Star pattern programs:

More C programs:

C Tutorials with simple Examples:

 

 

Venkat

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

1 Response

  1. June 26, 2021

    […] Pattern 8: Rhombus Star Pattern Program […]

Leave a Reply