C Program To Print Diamond Pattern Last Updated : 10 Dec, 2024 Comments Improve Suggest changes 4 Likes Like Report The Diamond Pattern is a symmetrical shape where the number of characters increases up to the centre and then decreases forming a diamond-like structure. It can be visualized as a full pyramid and an inverted full pyramid joined by their bases. In this article, we will learn how to print the Diamond Pattern using C program. Program To Print Diamond Pattern Star Pattern #include <stdio.h> int main() { int n = 5; // First outer loop to iterator through each row for (int i = 0; i < 2 * n - 1; i++) { // Assigning values to the comparator according to // the row number int comp; if (i < n) comp = 2 * (n - i) - 1; else comp = 2 * (i - n + 1) + 1; // First inner loop to print leading whitespaces for (int j = 0; j < comp; j++) printf(" "); // Second inner loop to print stars * for (int k = 0; k < 2 * n - comp; k++) { printf("* "); } printf("\n"); } return 0; } Number Pattern #include <stdio.h> int main() { int n = 5; // First outer loop to iterator through each row for (int i = 0; i < 2 * n - 1; i++) { // Assigning values to the comparator according to // the row number int comp; if (i < n) comp = 2 * (n - i) - 1; else comp = 2 * (i - n + 1) + 1; // First inner loop to print leading whitespaces for (int j = 0; j < comp; j++) printf(" "); // Second inner loop to print stars * for (int k = 0; k < 2 * n - comp; k++) { printf("%d ", k + 1); } printf("\n"); } return 0; } Alphabet Pattern #include <stdio.h> int main() { int n = 5; // First outer loop to iterator through each row for (int i = 0; i < 2 * n - 1; i++) { // Assigning values to the comparator according to // the row number int comp; if (i < n) comp = 2 * (n - i) - 1; else comp = 2 * (i - n + 1) + 1; // First inner loop to print leading whitespaces for (int j = 0; j < comp; j++) printf(" "); // Second inner loop to print stars * for (int k = 0; k < 2 * n - comp; k++) { printf("%c ", k + 'A'); } printf("\n"); } return 0; } Output * | 1 | A * * * | 1 2 3 | A B C * * * * * | 1 2 3 4 5 | A B C D E * * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H I * * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G * * * * * | 1 2 3 4 5 | A B C D E * * * | 1 2 3 | A B C * | 1 | AExplanation:Outer loop iterates through each row from 0 to 2 * n - 2 (as total 2 * n - 1 rows).comp determines the number of leading spaces based on the current row number.For the first half (i < n): comp = 2 * (n - i) - 1.For the second half (i >= n): comp = 2 * (i - n + 1) + 1.First inner loop prints leading white spaces in each row.Second inner loop iterates through the columns in the row to print * star.After completing a row, printf("\n") moves to the next line. Comment M mukulsomukesh Follow 4 Improve M mukulsomukesh Follow 4 Improve Article Tags : C Programs C Language C Pattern Programs Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like