Write a C Graphics Program to draw a Straight Line
#include<stdio.h> #include<conio.h> #include<graphics.h> main() { int gd=DETECT, gm, x1, y1, x2, y2; initgraph(&gd, &gm, "C:\\TC\\BGI"); clrscr(); printf("Enter the start point coordinate:"); scanf("%d%d", &x1,&y1); printf("Enter the end point coordinate:"); scanf("%d%d", &x2,&y2); setbkcolor(DARKGRAY); setcolor(RED); line(x1, y1, x2, y2); outtextxy(20, 450, "Press any key to continue..."); getch(); closegraph(); return 0; }
Output: