Hollow Diamond Pattern in C

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

There are many pattern programs are written by programmers for practice purposes. The diamond pattern programs are one of them. Here we will write a hollow diamond pattern in C.

Hollow Diamond Star Pattern in C

Input: 5

Output:
     *
    * *
   *   *
  *     *
 *       *
  *     *
   *   *
    * *
     *

C program for the above pattern,

#include<stdio.h>
int main()
{
  int n;

  printf("Enter number of rows: ");
  scanf("%d",&n);

  for(int i=1; i<=n; i++)
  {
     for(int j=i; j<=n; j++)
     {
       printf(" ");
     }
     for(int k=1; k<=2*i-1; k++)
     {
       if(k==1 || k==(2*i-1)) printf("*");
       else printf(" ");
     }
     printf("\n");
  }

  for(int i=n-1; i>=1; i--)
  {
     for(int j=n; j>=i; j--)
     {
       printf(" ");
     }
     for(int k=1; k<=2*i-1; k++)
     {
       if(k==1 || k==2*i-1) printf("*");
       else printf(" ");
     }
     printf("\n");
  }

  return 0;
}

Output:-

Enter number of rows: 7

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

In this pattern first and the last row contain 1 star and remaining every row contains exactly 2 stars.

We can display any characters instead of stars, for this purpose just replace the * with that character. But in this case, all characters must be the same.

Hollow Diamond Number Pattern

Input: 5

Output:

     1
    2 2
   3   3
  4     4
 5       5
  4     4
   3   3
    2 2
     1

This hollow diamond pattern contains numbers instead of stars. So, only some parts of the code will change and others will remain the same.

The pattern starts with 1 and displays up to 5. The first and last row contains only 1 and the remaining rows contains exactly 2 same numbers. From 1st to 5th row the size of pattern increases and from 6th to 9th row the size of pattern decreased.

#include<stdio.h>
int main()
{
   int n, a=1;

   printf("Enter number of rows: ");
   scanf("%d", &n);

   for(int i=1; i<=n; i++)
   {
     for(int j=i; j<=n; j++)
     {
       printf(" ");
     }
     for(int k=1; k<=2*i-1; k++)
     {
       if(k==1 || k==2*i-1) printf("%d",a);
       else printf(" ");
     }
     a++;
     printf("\n");
   }

   a=n-1;

   for(int i=n-1; i>=1; i--)
   {
     for(int j=n; j>=i; j--)
     {
       printf(" ");
     }
     for(int k=1; k<=2*i-1; k++)
     {
       if(k==1 || k==2*i-1) printf("%d",a);
       else printf(" ");
     }
     a--;
     printf("\n");
   }

   return 0;
}

Output:-

Enter number of rows: 3
   1
  2 2
 3   3
  2 2
   1
Enter number of rows: 5
     1
    2 2
   3   3
  4     4
 5       5
  4     4
   3   3
    2 2
     1

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Similar C programs

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Reply