显示边长为100的等边三角形用c语音
时间: 2023-09-10 18:01:53 浏览: 42
要显示一个边长为100的等边三角形,可以使用C语言中的图形库来实现。下面是一个简单的示例代码:
```c
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // 初始化图形界面
int centerX = getmaxx() / 2; // 获取屏幕中心点的横坐标
int centerY = getmaxy() / 2; // 获取屏幕中心点的纵坐标
int sideLength = 100; // 三角形的边长
// 计算三角形三个顶点的坐标
int x1 = centerX;
int y1 = centerY - sideLength / 2;
int x2 = centerX - sideLength / 2;
int y2 = centerY + sideLength / 2;
int x3 = centerX + sideLength / 2;
int y3 = y2;
// 使用画线函数绘制三角形
line(x1, y1, x2, y2);
line(x1, y1, x3, y3);
line(x2, y2, x3, y3);
getch(); // 等待用户按下任意键继续
closegraph(); // 关闭图形界面
return 0;
}
```
以上代码会在屏幕上显示一个边长为100的等边三角形,其中的图形库函数使用的是BGI图形库。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)