Re: [問題] 北大95

看板TransCSI作者 (小葉子)時間18年前 (2007/05/29 16:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《XrGodz (G_z*)》之銘言: : 使用C或C++程式語言設計一個列印數字菱形的程式。 : 輸入一個正整數N,將越大的數字擺在越外圈,依次向內遞減,中央數字是1。 : EX: : Input:3 Input:5 : Output: Output: : 3 5 : 323 545 : 32123 54345 : 323 5432345 : 3 543212345 : 5432345 : 54345 : 545 : 5 : 下面是我寫的... : for(i-> 0 to 2n-1 ) : for(j-> n to 1) : for(k-> 1 to j-1) : print("△") : for(l-> n to j) : print("l") : for(m-> j+1 to n) : print("m") : for(p-> 1 to n) : for(q-> j-1 to 1) : print("△") : for(r-> n to p) : print("r") : for(s-> p+1 to n) : print("s") : 這樣意思對嗎? : 如果把它改寫成C : 那for迴圈要怎樣表示? 我覺得你有些些地方怪怪的... 我把我的答案給你好了... #include<stdio.h> main(){ int n,i,j; printf("Please input a number: "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n-i;j++) printf(" "); for(j=n;j>n-i;j--) printf("%d ",j); for(++j;j<n;j++) printf("%d ",j+1); printf("\n"); } for(i=n-1;i>=1;i--){ for(j=1;j<=n-i;j++) printf(" "); for(j=n;j>n-i;j--) printf("%d ",j); for(++j;j<n;j++) printf("%d ",j+1); printf("\n"); } system("pause"); } 這是寫好的執行檔~~ http://w1.loxa.com.tw/ahong/knowledge/kn004.EXE -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.32.125.13
文章代碼(AID): #16M-Vboq (TransCSI)
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
3
3
完整討論串 (本文為第 2 之 2 篇):
問題
3
3
文章代碼(AID): #16M-Vboq (TransCSI)