C Program to Print Pyramid Numbers Pattern

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

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Pyramid Number Pattern Rows = ");
	scanf("%d", &rows);

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

This C program prints the pyramid pattern of numbers using a while loop.

#include <stdio.h>

int main()
{
	int i, j, k, rows;

	printf("Enter Pyramid Number Pattern Rows = ");
	scanf("%d", &rows);

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

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

		k = 1;
		while (k <= i)
		{
			printf("%d ", i);
			k++;
		}

		printf("\n");
		i++;
	}
}
Enter Pyramid Number Pattern Rows = 8
Printing Pyramid Number Pattern
       1 
      2 2 
     3 3 3 
    4 4 4 4 
   5 5 5 5 5 
  6 6 6 6 6 6 
 7 7 7 7 7 7 7 
8 8 8 8 8 8 8 8

This C example uses the do while loop to print the pyramid pattern of numbers.

#include <stdio.h>

int main()
{
	int i, j, k, rows;

	printf("Enter Pyramid Number Pattern Rows = ");
	scanf("%d", &rows);

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

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

		} while (j-- > i);

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

		} while (++k <= i);

		printf("\n");

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