Write a C program to make such a pattern as a pyramid with an asterisk.

Function Main
    Declare Integer i, j, space, rows, k
    Output "Input number of rows : "
    Input rows
    Assign space = rows+4-1
    For i = 1 to rows
        For k = space to 1 decreasing
            Output " "
        End
        For j = 1 to i
            Output "* "
        End
        Output ""
        Assign space = space -1
    End
End

#include <stdio.h>
int main()
{
   int i,j,space,rows,k;
   printf("Input number of rows : ");
   scanf("%d",&rows);
   space=rows+4-1;
   for(i=1;i<=rows;i++)
   {
         for(k=space;k>=1;k--)
            {
              printf(" ");
            }
                      
	   for(j=1;j<=i;j++)
	   printf("* ");
	printf("\n");
    space--;
   }
 return 0;
}

Input number of rows  : 4                                                                                     
       *                                                                                                      
      * *                                                                                                     
     * * *                                                                                                    
    * * * * 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.