Diamond Pattern Program in C

In this section you will learn how to print diamond pattern in c in easy way. We will print the diamond pattern with help of for loop condition and then we will show the output on screen. In this program we are taking the input from user.

Diamond Pattern Program

How program will work?

First part of loop printing below pattern:


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

Second part of loop printing below pattern:


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

Program of print diamond pattern in c


	#include<stdio.h>
	#include<conio.h>

	//DIAMOND PATTERN PROGRAM
	void main()
	{
   	   int value, i, j, k;
	   clrscr();
	   
	   printf("PROGRAM FOR DISPLAYING DIAMOND PATTERN OF *.");
	   printf("ENTER NUMBER TO PRINT THE DIAMOND:- ");
	   scanf("%d",&value);
	   
	   //FIRST PART OF LOOP
	   for(i=1; i<=value; i++)
	   {
	   	for(j=0; j<=(value-i); j++)
		{
		    printf(" ");
		}
		
		for(j=1; j<=i; j++)
		{
		    printf("*");
		}
		for(k=1; k<i; k++)
		{
		   printf("*");
		}
		printf("\n");
	   }
	   
	   //SECOND PART OF LOOP
	   for(i=value-1; i>=1; i--)
	   {
	   	for(j=0; j<=(value-i); j++)
		{
		    printf(" ");
		}
		
		for(j=1; j<=i; j++)
		{
		    printf("*");
		}
		for(k=1; k<i; k++)
		{
		   printf("*");
		}
		printf("\n");
	   }
	   
	   getch();
	 }

Output:


	PROGRAM FOR DISPLAYING DIAMOND PATTERN OF *.
	ENTER NUMBER TO PRINT THE DIAMOND:- 5
	
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *
      * * * * * * *
        * * * * *
          * * *
            *

Post Your Comment