How do you write a program that draws a rectangle using turbo pascal?

1 answer

Answer

1165136

2026-05-19 02:35

+ Follow

To draw a rectangle in Turbo Pascal, you can use the Rectangle procedure from the Graph unit. First, initialize the graphics mode with InitGraph, then specify the coordinates for the top-left and bottom-right corners of the rectangle. Use the Rectangle function with these coordinates, and finally, use CloseGraph to exit the graphics mode. Here’s a simple example:

<code class="language-pascal">uses Graph;

var gd, gm: Integer;

begin gd := Detect; InitGraph(gd, gm, ''); Rectangle(100, 100, 300, 200); // Draws a rectangle ReadLn; // Wait for user input CloseGraph; end.

</code>
ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.