C Program to Print Diamond Pattern

This C Program prints diamond pattern.

Here is source code of the C Program to print diamond pattern. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Print Diamond Pattern
  3.  */
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     int number, i, k, count = 1;
  9.  
  10.     printf("Enter number of rows\n");
  11.     scanf("%d", &number);
  12.     count = number - 1;
  13.     for (k = 1; k <= number; k++)
  14.     {
  15.         for (i = 1; i <= count; i++)
  16.             printf(" ");
  17.         count--;
  18.         for (i = 1; i <= 2 * k - 1; i++)
  19.             printf("*");
  20.         printf("\n");
  21.      }
  22.      count = 1;
  23.      for (k = 1; k <= number - 1; k++)
  24.      {
  25.          for (i = 1; i <= count; i++)
  26.              printf(" ");
  27.          count++;
  28.          for (i = 1 ; i <= 2 *(number - k)-  1; i++)
  29.              printf("*");
  30.          printf("\n");
  31.       }
  32.       return 0;
  33. }


$ cc pgm60.c
$ a.out
Enter number of rows
5
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
$ a.out
Enter number of rows
2
 *
***
 *

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you liked this C Program, kindly share, recommend or like below!

About

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Sanfoundry Training Center of Excellence (CoE)

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.







Subscribe Newsletter & Posts
Sanfoundry Internships
Follow Manish & Sanfoundry