Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 58

C Exercise 58

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Learn to use rectangle to draw a square. (Implemented in TC).

**Analysis:** None.

Program source code:



//  Created by www.runoob.com on 15/11/9.

//  Copyright © 2015 Runoob Tutorial. All rights reserved.

//



#include "graphics.h"

int main()

{

    int x0,y0,y1,x1,driver,mode,i;

    driver=VGA;mode=VGAHI;

    initgraph(&driver,&mode,"");

    setbkcolor(YELLOW);

    x0=263;y0=263;y1=275;x1=275;

    for(i=0;i<=18;i++)

    {

        setcolor(1);

        rectangle(x0,y0,x1,y1);

        x0=x0-5;

        y0=y0-5;

        x1=x1+5;

        y1=y1+5;

    }

    settextstyle(DEFAULT_FONT,HORIZ_DIR,2);

    outtextxy(150,40,"How beautiful it is!");

    line(130,60,480,60);

    setcolor(2);

    circle(269,269,137);

}

100 Classic C Language Examples 100 Classic C Language Examples