print diamond with space Pattern using C

#include<stdio.h>

int main()
{
int h,i,j;

printf("Enter the height");
scanf("%d",&h);


for(i=1;i<=h;i++)
{
 for(j=1;j<20-i;j++)
  printf("  ");
 for(j=1;j<=i;j++)
  {
  if(j==1 || j==i)
  printf("%c ",64+j);
  else
  printf("  ");
  }
 for(j=j-2;j>=1;j--)
  {
  if(j==1 || j==j-2)
   printf("%c ",64+j);
  else
   printf("  ");
  }
 printf("\n");
}
for(i=h-1;i>=1;i--)
{
 for(j=1;j<20-i;j++)
  printf("  ");
 for(j=1;j<=i;j++)
  {
  if(j==1 || j==i)
  printf("%c ",64+j);
  else
  printf("  ");
  }
 for(j=j-2;j>=1;j--)
  {
  if(j==1 || j==j-2)
  printf("%c ",64+j);
  else
  printf("  ");
  }
 printf("\n");
}

}




Comments

Popular posts from this blog

JAVA program to add two distance

Print Pattern using C