Software & Finance





Turbo C - Build Outline Diamond Pattern of *





This program is written in Turbo C programming language and will accept a number as input. The loops are used to build outline diamond pattern of * with out filling * inside the diamond.

 


Source Code



#include 
#include 
#include 
#include 

void main()
{
   int i, j, k;
   int n = 0;

   printf("Program for displaying pattern of *.\n");
   printf("Enter the maximum number of *: ");
   scanf("%d", &n);

   printf("\nHere is the Diamond of Stars\n");

   for (i = 1; i <= n; i++)
   {
      for (j = 0; j < (n - i); j++)
         printf(" ");
      for (j = 1; j <= i; j++)
         if(j == 1) printf("*"); else printf(" ");
      for (k = 1; k < i; k++)
         if(k == i - 1) printf("*"); else printf(" ");
      printf("\n");
   }

   for (i = n - 1; i >= 1; i--)
   {
      for (j = 0; j < (n - i); j++)
         printf(" ");
      for (j = 1; j <= i; j++)
         if(j == 1) printf("*"); else printf(" ");
      for (k = 1; k < i; k++)
         if(k == i - 1) printf("*"); else printf(" ");
      printf("\n");
   } 
   printf("\n");
}

Output