├── Diamond Pattern ├── Full Pyramid Pattern └── Number pattern /Diamond Pattern: -------------------------------------------------------------------------------- 1 | //Diamond pattern of stars using C 2 | #include 3 | int main() 4 | { 5 | int n = 7; 6 | 7 | // first outer loop to iterate through each row 8 | for (int i = 0; i < 2 * n - 1; i++) { 9 | 10 | // assigning values to the comparator according to 11 | // the row number 12 | int comp; 13 | if (i < n) { 14 | comp = 2 * (n - i) - 1; 15 | } 16 | else { 17 | comp = 2 * (i - n + 1) + 1; 18 | } 19 | 20 | // first inner loop to print leading whitespaces 21 | for (int j = 0; j < comp; j++) { 22 | printf(" "); 23 | } 24 | 25 | // second inner loop to print stars * 26 | for (int k = 0; k < 2 * n - comp; k++) { 27 | printf("* "); 28 | } 29 | printf("\n"); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Full Pyramid Pattern: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int rows = 7; 6 | 7 | // first loop to print all rows 8 | for (int i = 0; i < rows; i++) { 9 | 10 | // inner loop 1 to print white spaces 11 | for (int j = 0; j < rows - i - 1; j++) { 12 | printf(" "); 13 | } 14 | 15 | // inner loop 2 to print star * character 16 | for (int k = 0; k < 2 * i + 1; k++) { 17 | printf("*"); 18 | } 19 | printf("\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Number pattern: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | scanf("%d",&n); 7 | for(int i=n;i>=1;i--) 8 | { 9 | for(int j=n;j>=1;j--) 10 | { 11 | for(int k=1;k<=i;k++) 12 | { 13 | printf("%d",j); 14 | } 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | --------------------------------------------------------------------------------