Re: [問題] 關於畫三角形

看板C_and_CPP作者 (To littlepig with love)時間15年前 (2010/11/06 21:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/10 (看更多)
※ 引述《laiis (你今天集點了嗎?)》之銘言: : 新手如我也想知道有沒有最佳寫法 @.@ : 底下是我的想法... : #include<stdio.h> : #include<stdlib.h> : int main(void){ : int hei; : printf("請輸入金字塔高度︰"); : scanf("%d",&hei); : int n=1; : int m=hei-n; : for(int i=0;i<hei;i++){ : for(int j=0;j<m+n;j++){ : printf((j<(m+n)-n)?" ":"X"); : } : printf("\n"); : m--; : n+=2; : } : return 0; : } 借用一下你的 code,參考看看: #include <iostream> #include <iomanip> #include <cstdlib> #include <cmath> using namespace std; int main(int argc, char *argv[]) { int i,j; int H; cout << "請輸入金字塔高度︰"; cin >> H; for ( i = 0; i < H; i++ ) { for ( j = 1-H; j <= H-1; j++ ) { cout << ( ( abs(j) <= i ) ? "*" : " " ); } cout << endl; } return ( 0 ); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.143.100 ※ 編輯: bigpigbigpig 來自: 114.37.143.100 (11/06 21:34)
文章代碼(AID): #1CrLZGO- (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1CrLZGO- (C_and_CPP)