C program to print triangle pattern of numbers

Here's a C program to print a triangle pattern of numbers:

#include <stdio.h>

int main() {
    int n, num = 1;

    printf("Enter the number of rows: ");
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            printf("%d ", num);
            num++;
        }
        printf("\n");
    }

    return 0;

This program will create a triangle pattern of numbers based on the number of rows you input. It prints numbers in an ascending order, starting from 1 and incrementing for each row.

For example, if you input 4 for the number of rows, the program will generate the following triangle pattern:

1
2 3
4 5 6
7 8 9 10  

You can adjust the number of rows by changing the value you enter when prompted.

Prasun Barua

Prasun Barua is an Engineer (Electrical & Electronic) and Member of the European Energy Centre (EEC). His first published book Green Planet is all about green technologies and science. His other published books are Solar PV System Design and Technology, Electricity from Renewable Energy, Tech Know Solar PV System, C Coding Practice, AI and Robotics Overview, Robotics and Artificial Intelligence, Know How Solar PV System, Know The Product, Solar PV Technology Overview, Home Appliances Overview, Tech Know Solar PV System, C Programming Practice, etc. These books are available at Google Books, Google Play, Amazon and other platforms.

*

Post a Comment (0)
Previous Post Next Post