Basic Right Triangle Number Pattern (Inverted)

Program to Print Basic Right Triangle Number Pattern (Inverted)

PRINTING PATTERN:

10987
456
32
1
            

PREREQUISITE:

Basic knowledge of C language and loops.

ALGORITHM:

1. Take the number of rows (n) as input from the user. This will determine the height of the inverted triangle.
2. Initialize a variable (let's call it 'num') to 10. This variable will be used to print the numbers in the pattern, starting from 10.
3. Initialize a loop that runs from n down to 1 (inclusive) to iterate through each row.
4. For each row (let's call the current row index 'i'), initialize another loop that runs from 1 to 'i' (inclusive) to print the numbers in that row.
5. Inside the inner loop, print the current value of 'num', and then decrement 'num' by 1.
6. After finishing the inner loop for a row, print a newline character to move to the next row.
7. Repeat steps 3 to 6 until all rows are printed.

Code in C:

#include <stdio.h>

int main() {
    int n, i, j, num;  // Declaring integers for rows, loop counters, and the starting number
    printf("Enter the number of rows for the inverted right triangle number pattern:\n");
    scanf("%d", &n);  // Taking input for number of rows
    num = 10;  // Starting number

    // Loop to print the inverted right triangle number pattern
    for (i = n; i >= 1; i--) {  // Loop for each row
        for (j = 1; j <= i; j++) {  // Loop for each column in the current row
            printf("%d", num);  // Printing the current number
            num--;  // Decrementing the number
        }
        printf("\n");  // New line after each row
    }

    return 0;
}
            

Output:

Enter the number of rows for the inverted right triangle number pattern:
4
10987
456
32
1