---
# System prepended metadata

title: 各種圖形挑戰
tags: [補充_st]

---

---
title: 各種圖形挑戰
tags: 補充_st
---
> [各種圖形挑戰題目](https://hackmd.io/@futurenest/code_supplement_1)

> [程式線上編譯環境](https://replit.com/)
:::warning
繳交規範（可以複製這裡的喔）

`### 自己名字`
`#### 題目一` 
```python
程式碼
```
`#### 題目二` 
```c++
程式碼
```
:::

---

### 王政翔
#### 實心三角形-1
```cpp=
//1
#include <iostream>
using namespace std;

int main(){
    int i, j;
    for(i = 1; i < 6; i++){
        for(j = 1; j <= i; j++){
	      cout << "* ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 實心三角形-2
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j, z;
    for(i = 1; i < 6; i++){
        for(j = 5; j > i; j--){
	      cout << "  ";
	  }
	  for(z = 1; z <= i; z++){
	      cout << "* ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 實心三角形-3
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j, z;
    for(i = 1; i < 6; i++){
        for(j = 1; j < i; j++){
	      cout << "  ";
	  }
	  for(z = 6; z > i; z--){
	      cout << "* ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 實心三角形-4
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    for(i = 1; i < 6; i++){
        for(j = 5; j >= i; j--){
	      cout << "* ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 空心三角形
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    for(i = 1; i < 6; i++){
        for(j = 1; j <= i; j++){
        	if(j == 1 || j == i || i == 5){
		    cout << "* ";
		} else {
		    cout << "  ";
		}
        }
        cout << endl;
    }
    
    return 0;
}
```
#### 實心方形
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    for(i = 1; i < 6; i++){
        for(j = 1; j < 6; j++){
	      cout << "* ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 空心方形
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    for(i = 1; i < 6; i++){
        for(j = 1; j < 6; j++){
	      if(j == 1 || j == 5 || i == 1 || i == 5){
		    cout << "* ";
		} else {
		    cout << "  ";
		} 
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 金字塔
```cpp=
#include <iostream>
using namespace std;

int main(){
    int i, j, z;
    for(i = 1; i < 6; i++){
        for(j = 4; j >= i; j--){
	      cout << "  ";
	  }
	  for(z = 1; z <= i; z++){
	      cout << "* ";
	      cout << "  ";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 菱形
```cpp=
#include <iostream>
using namespace std;

int main(){
    for(int i = 1; i < 6; i++){
        for(int j = 4; j >= i; j--){
	      cout << " ";
	  }
	  for(int z = 1; z <= i+i-1; z++){
	      cout << "*";
	  }
	  
	  cout << endl;
    }
    for(int i = 1; i < 6; i++){
        for(int j = 1; j <= i; j++){
	      cout << " ";
	  }
	  for(int z = 7; z >= i+i-1; z--){
	      cout << "*";
	  }
	  cout << endl;
    }
    
    return 0;
}
```
#### 空心菱形
```cpp=
#include <iostream>
using namespace std;

int main(){
    for(int i = 1; i < 6; i++){
        for(int j = 4; j >= i; j--){
	      cout << " ";
	  }
	  for(int z = 1; z <= i+i-1; z++){
	      if(z == 1 || z == i+i-1 || i == i+i-1){
		    cout << "*";
		} else {
		    cout << " ";
		}
	  }
	  cout << endl;
    }
    
    for(int i = 1; i < 6; i++){
        for(int j = 1; j <= i; j++){
	      cout << " ";
	  }
	  for(int z = 7; z >= i+i-1; z--){
	      if(z == 7 || z == i+i-1){
		    cout << "*";
		} else {
		    cout << " ";
		}
	  }
	  cout << endl;
    }
    
    return 0;
}
```
----------------------------------------------------
### 林永晉
#### 實心三角形-1
```python=
for i in range(1,6):
    print('* ' * i)
```
#### 實心三角形-2
```python=
for i in range(1,6):
    for j in range(5,0,-1):
        if i < j:
            print('  ',end='')
        else:
            print('* ',end='')
    print()
```
#### 實心三角形-3
```python=
for i in range(0,6):
    for j in range(1,6):
        if i < j:
            print('* ',end='')
        else:
            print('  ',end='')
    print()
```
#### 實心三角形-4
```python=
for i in range(5,0,-1):
    print('* ' * i)
```
#### 空心三角形
```python=
for i in range(1,3):
    print('* ' * i)
for i in range(2):
    print('* ','  ' * i,'*')
for i in range(5):
    print('* ',end='')
```
#### 實心方形
```python=
for i in range(1,6):
    for j in range(1,6):
        print('*  ',end='')
        if j % 5 == 0:
           print()
```
#### 空心方形
```python=
print('*  ' * 5)
for i in range(3):
    print('*  ','  ' * 3,' *')
print('*  ' * 5)
```
#### 金字塔
```python=
for i in range(1,6):
    print('  ' * (5 - i) + ' *  ' * i)
```
#### 菱形
```python=
for i in range(1,5):
    print(' ' * (6 - i) + '*' * (2 * i - 1))   #只print到第四行
for i in range(5,0,-1):
    print(' ' * (6 - i) + '*' * (2 * i - 1))
```
#### 空心菱形
```python=
for i in range(1,6):
    for j in range(6 - i):
        print(' ', end='')
    for k in range(i):
        if k == 0 or k == i - 1:
            print('*', end=' ')
        else:
            print(end='  ')
    print()
for i in range(4,0,-1):
    for j in range(6 - i):
        print(' ', end='')
    for k in range(i):
        if k == 0 or k == i - 1:
            print('*', end=' ')
        else:
            print(end='  ')
    print()
```
---------------------------------------------

