如果真的要動態決定數目的話
需要動態產生所需 " " 和 "* " 的數目
不然也可以偷機, 給使用者一定不會超過的數目
複製程式
#include <stdio.h>
#include <stdlib.h>
char * space;
char * star;
void test(int max,int now){
  if(now==-max)
    return ;
  test(max,now-1);
  printf("%.*s",now<1?-now:now, space);
  printf("%.*s \n",(max-(now<1?-now:now))*2, star);
}
int main(){
  int n, i;
  printf("input n:");
  scanf("%d",&n);
  space = (char*)malloc(sizeof(char)*(n + 1));
  star  = (char*)malloc(sizeof(char)*(2*n + 1));
  for(i = 0; i < n; i++) {
    space[i] = 32; // " "
    star[2*i + 1] = 32; // " "
    star[2*i] = 42; // "*"
  }
  space[n] = 0;
  star[2*n] = 0;
  test(n,n);
  free(space);
  free(star);