C Program to Print Triangle Numbers Pattern

Write a C program to print triangle numbers pattern using for loop.

#include <stdio.h>

int main()
{
	int rows;
	
	printf("Enter Triangle Number Pattern Rows = ");
	scanf("%d", &rows);

	printf("Printing Triangle Number 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);
		}
		printf("\n");
	}
}
C Program to Print Triangle Numbers Pattern

This C example prints the triangle pattern of numbers using a while loop.

#include <stdio.h>

int main()
{
	int i, j, k, rows;
	
	printf("Enter Triangle Number Pattern Rows = ");
	scanf("%d", &rows);

	printf("Printing Triangle Number Pattern\n");
	i = 1;

	while (i <= rows)
	{
		j = rows;
		while (j > i)
		{
			printf(" ");
			j--;
		}

		k = 1;
		while (k <= i)
		{
			printf("%d ", k);
			k++;
		}
		printf("\n");
		i++;
	}
}
Enter Triangle Number Pattern Rows = 9
Printing Triangle Number Pattern
        1 
       1 2 
      1 2 3 
     1 2 3 4 
    1 2 3 4 5 
   1 2 3 4 5 6 
  1 2 3 4 5 6 7 
 1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 

C program to print triangle numbers pattern using a do while loop.

#include <stdio.h>

int main()
{
	int i, j, k, rows;
	
	printf("Enter Triangle Number Pattern Rows = ");
	scanf("%d", &rows);

	printf("Printing Triangle Number Pattern\n");
	i = 1;

	do
	{
		j = rows;
		do
		{
			printf(" ");

		} while (j-- > i);

		k = 1;
		do
		{
			printf("%d ", k);

		} while (++k <= i);
		printf("\n");

	} while (++i <= rows);
}
Enter Triangle Number Pattern Rows = 13
Printing Triangle Number Pattern
             1 
            1 2 
           1 2 3 
          1 2 3 4 
         1 2 3 4 5 
        1 2 3 4 5 6 
       1 2 3 4 5 6 7 
      1 2 3 4 5 6 7 8 
     1 2 3 4 5 6 7 8 9 
    1 2 3 4 5 6 7 8 9 10 
   1 2 3 4 5 6 7 8 9 10 11 
  1 2 3 4 5 6 7 8 9 10 11 12 
 1 2 3 4 5 6 7 8 9 10 11 12 13