Diamond Star Pattern
Here you will learn to print a Diamond Star Pattern in C programming language.
Diamond Star Pattern Program Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <stdio.h> int main() { int n = 5,i,j; printf("Enter a Number to print pattern of Diamond Star: "); scanf("%d",&n); // Design Upper half of diamond for (int i = 0; i < n; i++) { // Print spaces for (int j = n - 1; j > i; j--) { printf(" "); } // Print stars for (int k = 0; k < i + 1; k++) { printf("* "); } printf("\n"); } // Design Lower half of diamond for (int i = 1; i < n; i++) { // Print spaces for (int j = 0; j < i; j++) { printf(" "); } // Print stars for (int k = n - 1; k >= i; k--) { printf("* "); } printf("\n"); } return 0; } |
Output