*
***
*****
*******
*********
***********
*********
*******
*****
***
*
output like this~when use diamond(7,'*');
code:
int diamond(int i,char x)
{
if(i%2 == 0)
{
printf("error");
return 0;
}
for(int t=1; t<=(i-1)/2+1; t++)
{
int blank = (i-2*(t-1))/2;
while(blank > 0)
{
printf(" ");
blank--;
}
int p=2*(t-1);
while(p>=0)
{
printf("%c",x);
p--;
}
printf("\n");
}
for(int t=(i-1)/2;t>0;t--)
{
int blank = (i-2*(t-1))/2;
while(blank > 0)
{
printf(" ");
blank--;
}
int p=2*(t-1);
while(p>=0)
{
printf("%c",x);
p--;
}
printf("\n");
}
return 1;
}
ok done~