C++ 之 菱形
瞎写着玩
//======================================== //file head //======================================== #include <iostream> using namespace std; //======================================== //function declare //======================================== void BuildToChar (int $num, char $ch); //======================================== //mian //======================================== int main () { int num = 5; int blank_tmp = (num-1)/2; int brick_tmp = 1; char blank = ' '; char brick = '*'; for(int i=1; i<=num ; i++) { BuildToChar (blank_tmp, blank); BuildToChar (brick_tmp, brick); cout<<endl; if(i < ((num+1)/2)) { blank_tmp --; brick_tmp += 2; } else { blank_tmp ++; brick_tmp -= 2; } } system ("PAUSE"); return 0; } //======================================== //function //======================================== //BuildToChar void BuildToChar (int $num, char $ch) { for(int i=0; i<$num; i++){ cout<<$ch; } }
[2005-9-25 7:53]