记:
这里用到了printf("%*s%s%*s\n",n-i,"",arr,n-i,"");的写法,
其中%*s中的*代表该字符串s的个数,s为给字符串,
这写法一般用在打印中
AC代码:
1 #include <stdio.h> 2 #define MAX 50 3 4 int main(void) 5 { 6 int i,n; 7 char arr[MAX+1]; 8 scanf("%d",&n); 9 sprintf(arr,"%s","*"); 10 for (i = 1 ; i <= n ; i ++) 11 { 12 printf("%*s%s%*s\n",n-i,"",arr,n-i,""); 13 sprintf(arr,"%s%s",arr,"**"); 14 } 15 16 return 0; 17 }
原文地址:https://www.cnblogs.com/mind000761/p/8874760.html
时间: 2024-10-11 08:39:23