📜  在C图形中绘制矩形

📅  最后修改于: 2021-05-25 18:22:32             🧑  作者: Mango

rectangular()用于绘制矩形。绘制矩形需要左上角和右下角的坐标。左侧指定左上角的X坐标,顶部指定左上角的Y坐标,右侧指定右下角的X坐标,底部指定右下角的Y坐标。
句法 :

rectangle(int left, int top, int right, int bottom);

例子:

输入:左侧= 150,顶部= 250,右侧= 450,底部= 350;输出 : 输入:左侧= 150,顶部= 150,右侧= 450,底部= 450;输出 :

下面是矩形函数的实现:

// C program to draw a rectangle
#include 
  
// Driver code
int main()
{
    // gm is Graphics mode which is a computer display
    // mode that generates image using pixels.
    // DETECT is a macro defined in "graphics.h" header file
    int gd = DETECT, gm;
  
    // location of left, top, right, bottom
    int left = 150, top = 150;
    int right = 450, bottom = 450;
  
    // initgraph initializes the graphics system
    // by loading a graphics driver from disk
    initgraph(&gd, &gm, "");
  
    // rectangle function
    rectangle(left, top, right, bottom);
  
    getch();
  
    // closegraph function closes the graphics
    // mode and deallocates all memory allocated
    // by graphics system .
    closegraph();
  
    return 0;
}

输出:

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。