【图形】数字菱形
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void printspace(int);
void main()
{
int n, C_baseline, V_space, V_col_in_each_row, V_val, V_mid;
register int i, j;
scanf("%d", &n);
C_baseline = n + n - 1;//最中间那一行
V_space = 2 * (n - 1);//每行空格数
V_col_in_each_row = 1;//每行的字符数
for (i = 1;i <= n;i++)//打印上半递增部分
{
V_val = n;
V_mid = i;
printspace(V_space);
for (j = 1;j <= V_col_in_each_row;j++)
{
if (j < V_mid)
printf("%-2d", V_val--);
else if(j==V_mid)
printf("%-2d", V_val);
else
printf("%-2d", ++V_val);
}
printf("\n");
V_space -= 2;
V_col_in_each_row += 2;
}
V_col_in_each_row = C_baseline - 2;
V_space = 2;
for (i = 1;i <= n - 1;i++)//打印下半递减部分
{
V_val = n;
V_mid = n - i;
printspace(V_space);
for (j = 1;j <= V_col_in_each_row; j++)
{
if (j < V_mid)
printf("%-2d", V_val--);
else if(j==V_mid)
printf("%-2d", V_val);
else
printf("%-2d", ++V_val);
}
printf("\n");
V_space += 2;
V_col_in_each_row -= 2;
}
}
void printspace(int x)
{
register int i=1;
while (i <= x)
{
printf(" ");
i++;
}
}