洗长方形这个表述可能有些误解,因为“洗”通常与清洁有关,而不是与编程相关。如果你是想了解如何用编程语言来绘制或操作长方形,那么可以使用各种编程语言来实现。以下是一些示例:
Python:
```python
def print_rectangle(width, height):
for i in range(height):
for j in range(width):
print("*", end=" ")
print()
print_rectangle(5, 3)
```
C++:
```cpp
include using namespace std; void printRectangle(int width, int height) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << "* "; } cout << endl; } } int main() { printRectangle(5, 3); return 0; } ``` Java: ```java public class Rectangle { public static void main(String[] args) { printRectangle(5, 3); } public static void printRectangle(int width, int height) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { System.out.print("* "); } System.out.println(); } } } ``` JavaScript: ```javascript function printRectangle(width, height) { for (let i = 0; i < height; i++) { for (let j = 0; j < width; j++) { process.stdout.write("* "); } console.log(); } } printRectangle(5, 3); ``` C: ```csharp using System; class Program { static void Main() { PrintRectangle(5, 3); } static void PrintRectangle(int width, int height) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Console.Write("* "); } Console.WriteLine(); } } } ``` 这些示例展示了如何使用不同编程语言来打印一个简单的长方形。你可以根据需要调整宽度和高度参数,或者在程序中添加更多功能,例如计算长方形的面积和周长。