ALGO-145_蓝桥杯_算法训练_4-1打印下述图形

时间:2023-11-24 08:16:02

ALGO-145_蓝桥杯_算法训练_4-1打印下述图形

记:

这里用到了printf("%*s%s%*s\n",n-i,"",arr,n-i,"");的写法,

其中%*s中的*代表该字符串s的个数,s为给字符串,

这写法一般用在打印中

AC代码:

 #include <stdio.h>
#define MAX 50 int main(void)
{
int i,n;
char arr[MAX+];
scanf("%d",&n);
sprintf(arr,"%s","*");
for (i = ; i <= n ; i ++)
{
printf("%*s%s%*s\n",n-i,"",arr,n-i,"");
sprintf(arr,"%s%s",arr,"**");
} return ;
}