看板 NTUEE107HW 關於我們 聯絡資訊
※ 引述《BLD (走不出去..)》之銘言: : 唔..跟我寫的差不多.. : 而且也是用space 和star.. : 阿abs是絕對值函數噢?? 對啊... : 我那時不知道就用if了 : 還有哪個pause是啥阿 讓程式停下來...可以欣賞螢幕跑出來的結果 ※ 引述《phylin (神之領域)》之銘言: : 這是我寫的另一種版本 : ...寫的好像太囉唆點...>< : #include <iostream> : #include <cmath> : #include <cstdlib> : using std::cin; : using std::cout; : using std::endl; : int main() : { : int number; : cout << "Please enter how many lines you want to print: " << endl; : cout << "Please enter an odd number: "; : cin >> number; : int Line = 1, Space = 1, Star = 1; : for (Line; Line <= number ; Line++) : { : int a = abs((number+1)/2 - Line); : int b = 2*((number+1)/2 - a)-1; : for (Space = 1; Space <= a ; Space++) : cout << " "; : {for (Star = 1; Star <= b ; Star++) : cout << "*"; : } : cout << endl; : } : system ("PAUSE"); : return 0; : } : ※ 引述《whxu (ㄧㄟㄛ夫~好淫穢)》之銘言: : 課本 P167 2.58 --> 印出排列好的星號如下 : : * : *** : ***** : ******* : ********* : ******* : ***** : *** : * : 說是越減少程式碼越好......|| : #include <iostream> : using namespace std; : int main(void) : { : int i,j,k=2; : for(i=1;i>0;i+=k) { : for(j=0;j<(9-i)/2;j++) cout << " "; : for(j=0;j<i;j++) cout << "*"; : cout << "\n"; : if(i>7) k=-2; : } : return 0; : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.132.37 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.18.127 ※ 編輯: phylin 來自: 140.112.18.127 (10/07 20:57)