#!/Perlik, сделай вдухмерный симольный массив - "рисовать" надо в нем, а потом выведешь результат.
#include <stdio.h>
#include <stdlib.h>
#define SIZE_X 16
#define SIZE_Y 16
char buffer[SIZE_Y][SIZE_X];
void init_buffer()
{
int x, y;
for (y = 0; y < SIZE_Y; y++)
for (x = 0; x < SIZE_X; x++)
buffer[y][x] = ' ';
}
void draw_line(int x0, int y0, int x1, int y1)
{
float x, y;
float dx, dy;
int n;
if (abs(x1 - x0) > abs(y1 - y0))
{
n = abs(x1 - x0);
dx = (x1 > x0) ? 1 : -1;
if (y1 == y0)
dy = 0;
else
dy = ((float)(y1 - y0))/(float)abs(x1 - x0);
}
else if (abs(y1 - y0) > abs(x1 - x0))
{
n = abs(y1 - y0);
dy = (y1 > y0) ? 1 : -1;
if (x1 == x0)
dx = 0;
else
dx = ((float)(x1 - x0))/(float)abs(y1 - y0);
}
else
{
n = abs(x1 - x0);
dx = (x1 > x0) ? 1 : -1;
dy = (y1 > y0) ? 1 : -1;
}
x = x0;
y = y0;
do {
buffer[(int)(y + 0.5)][(int)(x + 0.5)] = '*';
x += dx;
y += dy;
}
while (n--);
}
void print_buffer()
{
int x, y;
for (y = 0; y < SIZE_Y; y++)
{
for (x = 0; x < SIZE_X; x++)
putchar(buffer[y][x]);
putchar('\n');
}
}
int main()
{
init_buffer();
draw_line(0, 0, 15, 8);
draw_line(15, 8, 7, 15);
draw_line(7, 15, 0, 0);
draw_line(0, 0, 15, 15);
draw_line(0, 15, 15, 0);
print_buffer();
return 0;
}