Autograder demo: Draw a triangle in C

In this question, we'll assume that there's a graphics library available that will allow us to draw lines on the screen. Such a library is not available with the system that we’re using but similar libraries are available on other systems, so the problems posed here are not unreasonable.

Assume the graphics library function is available to you:

1
2
/* draws a line from (x_start, y_start) to (x_end, y_end) */
void drawLine(int x_start, int y_start, int x_end, int y_end);

Your task is to write a function drawTri that draws right-angled, isosceles triangle on the screen where the parameters are:

  • side_length: the equal length of the two shorter sides,
  • x and y: the (coordinate) location of the upper vertex

Sample output are as follows (in red only):

Sample Output

Function call: drawTri(2, 0, 4);


Function call: drawTri(3, 0, 0);


Function call: drawTri(1, 1, 1);

Note: Your function is not expected to draw the axes and the dashed supporting-lines!

drawTri.c

Correct answer

Student view placeholder

In student views this area is used for assessment and score info.
Tools

Staff information

Question

Title:
Autograder demo: Draw a triangle in C

Variant

Started at:
2026-09-19 07:55:09 (CDT)
Duration:
0s
Show/Hide answer
{}
History
dec frac
rad deg