C Programming Code Examples C > Miscellaneous Code Examples C Program to Print Diamond Pattern C Program to Print Diamond Pattern - Take the number of rows as input. - According to the number of rows, print the " " and "*" using for loops. - Exit. #include <stdio.h> int main() { int number, j, k, count = 1; printf("Enter number of rows\n"); scanf("%d", &number); count = number - 1; for (k = 1; k <= number; k++) { for (j = 1; j <= count; j++) printf(" "); count--; for (j = 1; j <= 2 * k - 1; j++) printf("*"); printf("\n"); } count = 1; for (k = 1; k <= number - 1; k++) { for (j = 1; j <= count; j++) printf(" "); count++; for (j = 1 ; j <= 2 *(number - k)- 1; j++) printf("*"); printf("\n"); } return 0; } - Take the number of rows as input and store in the variable number. - Firstly decrement the variable number by 1 and assign this value to the variable count. - Use this variable count as terminator in the for loop to print " ". - Decrement count by 1. - Use another for loop starting from 1 to (2*k-1) to print "*". - Do steps 3, 4, and 5 inside the for loop starting from 1 to variable number. - Steps 2-6 are used to print half of the diamond pattern. - For the next half, assign the variable count by 1. - Use this variable count as terminator in the for loop to print " ". - Increment count by 1. - Use another for loop starting from 1 to (2*(number-k)-1) to print "*". - Do steps 8-11 inside the for loop starting from 1 to value (number-1).