本帖最後由 葉桔良 於 2022-10-15 20:55 編輯
利用巢狀迴圈, 試做一個長為10顆*, 高為4顆*, 之平行四邊形, 排列如下圖:
![](https://seed.istak.org.tw/attachment.php?aid=MTI0Mnw5NThiNjM3N3wxNDc3NzI0MDYwfDcwMDR4RWd4Mm1sMWpwZUh6aUxFa3R2MVM4eWd5dUErZm55a0wvSm1idEpMOXo4&noupdate=yes) - #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- for(int i = 0; i < 4;i++) //0~3 -> 4
- {
- for(int j = 0; j < 3-i;j++)
- {
- cout<<" ";
- }
- for(int k = 0; k < 10; k++)
- {
- cout<<"*";
- }
- cout<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |