Write a C program to print right pascals triangle of mirrored numbers pattern using for loop.
#include <stdio.h> int main() { int rows, i, j, k; printf("Enter Right Pascals Triangle Mirrored Numbers Rows = "); scanf("%d", &rows); printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n"); for (i = rows; i >= 1; i--) { for (j = i; j <= rows; j++) { printf("%d ", j); } for (k = rows - 1; k >= i; k--) { printf("%d ", k); } printf("\n"); } for (i = 2; i <= rows; i++) { for (j = i; j <= rows; j++) { printf("%d ", j); } for (k = rows - 1; k >= i; k--) { printf("%d ", k); } printf("\n"); } }
This C program prints the right pascals triangle pattern of mirrored numbers using a while loop.
#include <stdio.h> int main() { int rows, i, j, k; printf("Enter Right Pascals Triangle Mirrored Numbers Rows = "); scanf("%d", &rows); printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n"); i = rows; while (i >= 1) { j = i; while (j <= rows) { printf("%d ", j); j++; } k = rows - 1; while (k >= i) { printf("%d ", k); k--; } printf("\n"); i--; } i = 2; while (i <= rows) { j = i; while (j <= rows) { printf("%d ", j); j++; } k = rows - 1; while (k >= i) { printf("%d ", k); k--; } printf("\n"); i++; } }
Enter Right Pascals Triangle Mirrored Numbers Rows = 10
The Right Pascals Triangle of Mirrored Numbers Pattern
10
9 10 9
8 9 10 9 8
7 8 9 10 9 8 7
6 7 8 9 10 9 8 7 6
5 6 7 8 9 10 9 8 7 6 5
4 5 6 7 8 9 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 9 8 7 6 5 4
5 6 7 8 9 10 9 8 7 6 5
6 7 8 9 10 9 8 7 6
7 8 9 10 9 8 7
8 9 10 9 8
9 10 9
10
In this C example, we used the forloopIter function to display the right pascals mirrored numbers triangle pattern.
#include <stdio.h> void rightpascalMirrored(int rows, int i) { for (int j = i; j <= rows; j++) { printf("%d ", j); } for (int k = rows - 1; k >= i; k--) { printf("%d ", k); } } int main() { int rows, i; printf("Enter Right Pascals Triangle Mirrored Numbers Rows = "); scanf("%d", &rows); printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n"); for (i = rows; i >= 1; i--) { rightpascalMirrored(rows, i); printf("\n"); } for (i = 2; i <= rows; i++) { rightpascalMirrored(rows, i); printf("\n"); } }
Enter Right Pascals Triangle Mirrored Numbers Rows = 12
The Right Pascals Triangle of Mirrored Numbers Pattern
12
11 12 11
10 11 12 11 10
9 10 11 12 11 10 9
8 9 10 11 12 11 10 9 8
7 8 9 10 11 12 11 10 9 8 7
6 7 8 9 10 11 12 11 10 9 8 7 6
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
6 7 8 9 10 11 12 11 10 9 8 7 6
7 8 9 10 11 12 11 10 9 8 7
8 9 10 11 12 11 10 9 8
9 10 11 12 11 10 9
10 11 12 11 10
11 12 11
12