C Programs to Print Full start Pyramid Pattern

C-Pattern-Programs

In this article, we are going to learn about how to print a Full Pyramid pattern in C language.First we are going to print the full Pyramid pattern and then in next program we will print this Pyramid in the center of the screen.

  • How to print Full Pyramid pattern using * in C language.
  • How to print full Pyramid at Center of screen using * in C language.

How to print Full Pyramid Start pattern in C language


Desired Output for Size 5:
    *
   ***
  *****
 *******
*********

C Programs to Print Full start Pyramid Pattern

#include<stdio.h>
int main()
{
    int num, row, col;

    printf("Please enter the number of rows: ");
    scanf("%d",&num);

    for(row = 1; row <= num; row++)
    {
      for(int s=1; s<=num-row; s++) 
              printf(" ");
      for(col = 1;col <= (2*row-1);col++) 
              printf("*");

      printf("\n");
    }

    return 0;
}

Output

Please enter the number of rows: 5
    *
   ***
  *****
 *******
*********

Print full start Pyramid at Center of screen in C language


In this example, we are going to learn how to print the full pyramid at the center of screen.In this example, we will assume that screen width is 100 character.

Desired Output for Size 7:
                                    *
                                   ***
                                  *****
                                 *******
                                *********
                               ***********
                              *************

C Programs to Print Full start Pyramid Pattern at center of screen

#include<stdio.h>
int main()
{
   int num,screensize=100;

   printf("Please enter the number of rows: ");
   scanf("%d", &num);

   for(int i = 1; i <= num; i++)
   {
     for(int j = 1; j <= (screensize/2-i); j++)
     {
       printf(" "); 
     }

     for(int k = 1; k <= (2*i-1); k++)
     {
       printf("*");
     }

     printf("\n");
   }

   return 0;
}

Output

Please enter the number of rows: 5
                                                 *
                                                ***
                                               *****
                                              *******
                                             *********