打印空心字符菱形

版权声明:由陈庚汝编辑 https://blog.csdn.net/ChenGengru/article/details/84258940

在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* 空心数字梯形 */
/* written by Chen Gengru */
/* updated on 2018-11-19 */
int main()
{
	char cStart;
	int iLine;
	int i, j;
	
	scanf("%c%d", &cStart, &iLine);
	
	for (i = 1; i <= iLine; i++)
	{
		for (j = iLine-i; j > 0; j--)
		{
			printf(" ");
		}
		printf("%c", cStart+i-1);
		for (j = 1; j <= 2*i-3; j++)
		{
			if (j > 0)
			{
				printf(" ");
			}
		}
		if (i > 1)
		{
		printf("%c", cStart+i-1);	
		}
		printf("\n");
	}
	
	for (i = 1; i < iLine; i++)
	{
		for (j = 1; j <= i; j++)
		{
			printf(" ");
		}
		printf("%c", cStart+iLine-i-1);
		for (j=1; j <= 2*(iLine-i)-3; j++)
		{
			printf(" ");
		}
		if (i < iLine-1)
		{
			printf("%c", cStart+iLine-i-1);
		}
		printf("\n");
	}
	
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/ChenGengru/article/details/84258940