C Program to print Diamond Star Pattern!

Hi Students, let’s write another pattern program in C language!

Print Diamond star pattern using C program:

#include <stdio.h>
int main()
{
	
	int limit, space, i, j;
	//print a string about the program
	printf("C Program to print diamond pattern\n");
    printf("Enter the limit: ");
   	
	//get the limit
	scanf("%d", &limit);
	
	//print the first half of the pyramid	 
    
	space = limit; 
    
	for (i = 1; i <= limit; i++) {
        
		for (j = 1; j <= space; j++) {
            printf(" ");
        }
        
        space--;
 
        for (j = 1; j <= 2 * i - 1; j++) {
            printf("*");
        }
 
        printf("\n");
    }
 
	//print the second half of the pyramid	 
    
	space = 2;
    
    for (i = 1; i <= limit; i++) {
        for (j = 1; j <= space; j++) {
            printf(" ");
        }
        space++;
 
        for (j = 1; j <= 2 * (limit - i) - 1; j++) {
            printf("*");
        }
 
        printf("\n");
    }

}

Sample Output of the above program:

C Program to print diamond pattern
Enter the limit: 5
     *
    ***
   *****
  *******
 *********
  *******
   *****
    ***
     *

Enjoy Learning!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top