Write a C program to print triangle of mirrored numbers pattern using for loop.
#include <stdio.h> int main() { int rows; printf("Enter Traingle Mirrored Numbers Rows = "); scanf("%d", &rows); printf("Printing Traingle of Mirrored Numbers Pattern\n"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { printf(" "); } for (int k = 1; k <= i; k++) { printf("%d", k); } for (int l = i - 1; l >= 1; l--) { printf("%d", l); } printf("\n"); } }
This pattern example prints the triangle of mirrored numbers using a while loop.
#include <stdio.h> int main() { int i, j, k, l, rows; printf("Enter Traingle Mirrored Numbers Rows = "); scanf("%d", &rows); printf("\n"); i = 1; while (i <= rows) { j = rows; while (j > i) { printf(" "); j--; } k = 1; while (k <= i) { printf("%d", k); k++; } l = i - 1; while (l >= 1) { printf("%d", l); l--; } printf("\n"); i++; } }
Enter Traingle Mirrored Numbers Rows = 9
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321