题解 | #空心三角形图案#
空心三角形图案
https://www.nowcoder.com/practice/2ccc5fca423e47f0b622fe6f151cfab4
#include <stdio.h>
int main() {
int a,i,j;
while (scanf("%d", &a) != EOF) { // 注意 while 处理多个 case
// 64 位输出请用 printf("%lld") to
for(i = 1; i <= a; i ++)
{
for(j = 1; j <= i ; j ++)
{
if(i == 1 || i == a)
{
printf("* ");
}
if(i >= 2 && i < a)
{
if(j == 1)
{
printf("* ");
}
else if(j == i)
{
printf("* ");
printf("\n");
}
else
{
printf(" ");
}
}
else if(j == i)
{
printf("\n");
}
}
}
}
return 0;
}
三角形的变体,稍微有点难度
只要熟练掌握了if ,else,else if 语句就可以轻松化解
查看15道真题和解析
