Half Pyramid Program

Posted by Anoop Nair on September 4, 2017 Tags: C Programs

What are we going to create today?

Today we are going to create some Half Pyramids using numbers and symbols

  
    The pattern will look like the following.
    Half Pyramids
    1
    12
    123
    1234
    12345

    *
    **
    ***
    ****
    *****


    Inverted Half Pyramid
    12345
    1234
    123
    12
    1


    *****
    ****
    ***
    **
    *

  

Program In C

    
      void HalfPyramid(int rows);
      void HalfPyramidPattern(int rows);
      void InvertedHalfPyramid(int rows);
      void InvertedHalfPyramidPattern(int rows);

      void main(){
          int n;
          printf("Enter the total number of rows \n");
          scanf("%d", &n);
          printf("\n Half Pyramid with Numbers\n");
          HalfPyramid(n);
          printf("\n Half Pyramid with symbols\n");
          HalfPyramidPattern(n);
          printf("\n Inverted Half Pyramid with Numbers\n");
          InvertedHalfPyramid(n);
          printf("\n Inverted Half Pyramid with Symbols \n");
          InvertedHalfPyramidPattern(n);
      }

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

      void HalfPyramidPattern(int rows){
          int i, j ;
          for(i=1 ; i<= rows ;i++){
              for(j=1; j <=i; j++ ){
                 printf("*");
              }
              printf("\n");
          }
      }

      void InvertedHalfPyramid(int rows){
          int i,j;
          for(i= rows ; i> 0; i--){
              for(j=1; j<= i; j++){
                  printf("%d", j);
              }
              printf("\n");
          }
      }

      void InvertedHalfPyramidPattern(int rows){
          int i,j;
          for(i= rows ; i> 0; i--){
              for(j=1; j<= i; j++){
                  printf("*");
              }
              printf("\n");
          }
      }

    
  

Output output

Follow the following links to see more examples.


COMMENTS