#include <stdio.h>
void draw_triangle_fun(unsigned int length, unsigned int width)
{
unsigned int t_w, t_l;
char space = ' ', ch;
for (t_w = 0; t_w <= width; t_w++)
{
for (t_l = 0; t_l <= (length - t_w); t_l++)
{
ch = t_l + '0';
printf("%c", ch);
}
printf("\n");
}
for (t_w = 0; t_w <= width; t_w++)
{
for (t_l = 0; t_l <= t_w; t_l++)
{
ch = t_l + '0';
printf("%c", ch);
}
printf("\n");
}
for (t_w = 0; t_w <= width; t_w++)
{
for (t_l = 0; t_l <= length - t_w; t_l++)
{
printf("%c", space);
}
for (t_l = 0; t_l <= t_w; t_l++)
{
ch = t_l + '0';
printf("%c", ch);
}
printf("\n");
}
for (t_w = 0; t_w <= width; t_w++)
{
for (t_l = 0; t_l <= t_w; t_l++)
{
printf("%c", space);
}
for (t_l = 0; t_l <= length - t_w; t_l++)
{
ch = t_l + '0';
printf("%c", ch);
}
printf("\n");
}
}
int main()
{
unsigned int length, width;
printf("\nPlease enter length/width(1 ~ 9):");
scanf("%d", &width);
if (width > 9)
width = 9;
length = width;
printf("\n=============================================\n");
draw_triangle_fun(length, width);
printf("\n=============================================\n");
return 0;
}
Please enter length/width(1 ~ 9):9
=============================================
0123456789
012345678
01234567
0123456
012345
01234
0123
012
01
0
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
0123456789
012345678
01234567
0123456
012345
01234
0123
012
01
0
=============================================