Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //影印十字菱形
- //main.cpp
- //影印十字菱形2
- //原始參考資料來源:https://www.facebook.com/groups/1403852566495675/permalink/2187717024775888/
- //原作者:諸英雄
- //修改者:郭翔宇
- #include <cstdlib>
- #include <iostream>
- #include <string>
- using std::cout;
- using std::cin;
- int main(int argc, char *argv[])
- {
- system("color f0");
- //true == 1
- //false == 0
- bool minusFlag = false;
- int input = 0;
- int column = 1;
- //input 10
- cout << "請輸入高度:";
- cin >> input;
- while (column != 0)
- {
- for (int i = 1; i <= (input - column); i++)
- {
- cout << " ";
- }
- if (column == 1 || column == input)
- {
- for (int j = 1; j <= (2 * column - 1); j++)
- {
- cout << "#";
- }
- cout << "\n";
- }
- else if (column != 1 && column != input)
- {
- cout << "#";
- for (int j = 1; j <= ((2 * column - 3) / 2); j++)
- {
- cout << " ";
- }
- cout << "#";
- for (int j = 1; j <= ((2 * column - 3) / 2); j++)
- {
- cout << " ";
- }
- cout << "#";
- cout << "\n";
- }
- if (column == input)
- {
- minusFlag = true;
- }
- if (minusFlag == true)
- {
- column = column - 1;
- }
- else if (minusFlag == false)
- {
- column = column + 1;
- }
- }
- cout << "\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement