Tuesday , January 23 2018
Home / C / c program for diamond shape pattern #16

c program for diamond shape pattern #16

This is a C program for diamond shape pattern which can be both filled and empty. However this choice is left for the user who can enter their choice as per their requirement.

int main()
    char empty=' ',fill='e';
    int i,j,height;
    printf("\n enter the height for Diamond (odd number) :");
    printf("\nenter 'E' for empty and 'F' for filled figure : ");
    printf("\nenter the character for printing the shape : ");

        for(j=i;j<=height/2;j++)    // to print the empty spaces outside the shape for each line
        printf(" ");
        for(j=1;j<=2*i-1;j++)       // number of characters in the shape in ith line is 2*i-1 
            if(j==1 | j==2*i-1 | empty=='f' | empty=='F')  // 1. see explanation below the program
            printf(" ");
      for(i=height/2+1;i>0;i--)    // To print the lower half of the diamond pattern
      { printf("\n");
      printf(" ");
        if(j==1 | j==2*i-1 | empty=='f' | empty=='F')
        printf(" ");
      return 1;

Explanation:  1. the character will print if it is in the boundary condition of the pattern i.e the first ( j==1 ) character or the last ( j==2*i-1 ) character . Or the character will print if the user choice is f i.e fill and in the boundary.

Also See:   C program for Kruskal Algorithm


empty star pattern

Tags: burfi shaped pattern in c, diamond shape pattern in  c

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

One comment

  1. Subhadeep Banerjee

    Thanks dear!
    On the other websites they gave a wrong program with a fake output.
    But finally I got it here… It’s really easy and cool… (y)

Leave a Reply

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