生成字符金字塔函数

#include
void f(int n, char x)
{
	int i, j, count,flag;
	for (i = 1; i <= n; i++)
	{
		count = 0,flag=1;
		for (j = 1; j < 2 * n; j++)
		{
			if (j <= n - i+1)
			{
				if (j == n - i + 1)
				{
					printf("%c", x), count++, flag = 0;
					continue;
				}
				else
				{
					printf(" ");
					continue;
				}
			}
				if (count == i)
					break;
				if (flag == 0)
				{
					printf(" ");
					flag = 1;
					continue;

			    }
				if (flag == 1)
				{
					printf("%c", x), count++, flag = 0;
					continue;
				}
		}
		printf("\n");
	}
}
int main()
{
	int n;
	char x;
	scanf("%d %c", &n, &x);
	f(n, x);
}

你可能感兴趣的:(算法,数据结构)