引用 | 編輯
johnroyer
2005-10-13 18:21 |
樓主
▼ |
||
![]() #include <stdio.h> #include <stdlib.h> int main() { int a=0,b=0,chk=1,h; printf("input h:"); scanf("%d",&h); for(a=0;a<h;a++) printf(&q .. 訪客只能看到部份內容,免費 加入會員 ![]()
|
引用 | 編輯
mmpo
2005-10-14 23:06 |
1樓
▲ ▼ |
要比短是吧!~~~~
這個不用for和while也照畫.... #include <stdio.h> #include <stdlib.h> void test(int max,int now){ if(now==-max) return ; test(max,now-1); printf("%.*s",now<1?-now:now," "); printf("%.*s \n",(max-(now<1?-now:now))*2,"* * * * * * * * * * * "); } int main(){ int n=8; test(n,n); system("pause"); } ![]() |
引用 | 編輯
檸檬茶
2005-11-14 15:13 |
2樓
▲ ▼ |
我這個是按照上面那位大大所法表的
多加一些讓它能做更多種輸入變化 #include <stdio.h> #include <stdlib.h> void test(int max,int now){ if(now==-max) return ; test(max,now-1); printf("%.*s",now<1?-now:now," "); printf("%.*s \n",(max-(now<1?-now:now))*2,"* * * * * * * * * * * "); } int main(){ int n; printf("input n:"); scanf("%d",&n); test(n,n); system("pause"); } ![]() |
引用 | 編輯
youchun
2005-11-14 17:18 |
3樓
▲ |
如果真的要動態決定數目的話
需要動態產生所需 " " 和 "* " 的數目 不然也可以偷機, 給使用者一定不會超過的數目 複製程式 #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); ![]() |