Write a C program to print inverted triangle numbers pattern using for loop.
#include <stdio.h> int main() { int rows; printf("Enter Inverted Triangle Number Pattern Rows = "); scanf("%d", &rows); printf("Printing Inverted Triangle Number Pattern\n"); for (int i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) { printf(" "); } for (int k = 1; k <= rows - i + 1; k++) { printf("%d ", k); } printf("\n"); } }
This C example displays the inverted triangle pattern of numbers using a while loop.
#include <stdio.h> int main() { int rows, i, j, k; printf("Enter Inverted Triangle Number Pattern Rows = "); scanf("%d", &rows); printf("Printing Inverted Triangle Number Pattern\n"); i = 1; while (i <= rows) { j = 1; while (j < i) { printf(" "); j++; } k = 1; while (k <= rows - i + 1) { printf("%d ", k); k++; } printf("\n"); i++; } }
Enter Inverted Triangle Number Pattern Rows = 9
Printing Inverted Triangle Number Pattern
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
In this C pattern example, we used the do while loop to display the inverted triangle of numbers.
#include <stdio.h> int main() { int rows, i, j, k; printf("Enter Inverted Triangle Number Pattern Rows = "); scanf("%d", &rows); printf("Printing Inverted Triangle Number Pattern\n"); i = 1; do { j = 1; do { printf(" "); } while (j++ < i); k = 1; do { printf("%d ", k); } while (++k <= rows - i + 1); printf("\n"); } while (++i <= rows); }
Enter Inverted Triangle Number Pattern Rows = 6
Printing Inverted Triangle Number Pattern
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1