Thursday 3 October 2013

Printing '*' pattern in the shape of Pyramid using C

#include <stdio.h>
 main()
{
   int row, col, n, temp;
   printf("\n(There is) none worthy of worship except Allah(Subhanahu wa ta'ala).Muhammad(Sallallahu alayhi wasallam) is Messenger of ALLAH(Subhanahu wa ta'ala).\n");
   printf("Enter the number of rows in pyramid of stars you wish to see: ");
   scanf("%d",&n);
   temp = n;
   for ( row = 1 ; row <= n ; row++,temp-- )
   {
      for ( col = 1 ; col < temp ; col++ )
      {
         printf(" ");
      }
      for ( col = 1 ; col <= 2*row - 1 ; col++ )
      {
         printf("*");
      }
        printf("\n");
   }
}

No comments:

Post a Comment