关于画一条直线的,可显示不出直线,不知道哪里出了问题?特向大家求教!
#include <graphics.h> #include <conio.h> #include <stdio.h> #include <math.h> void midpoint(int x0,int y0,int x1,int y1,int color) {int dx,dy,d,x,y; dx=x1-x0; dy=y1-y0; m=dy/dx; d=dx-2*dy; x=x0;y=y0; putpixel(x,y,color); if(-1<m<1) while(x<x1) {if(d>0) d=d-2*dy; else {d=d-2*(dy-dx); y++;
x++;} putpixel(x,y,color);
} else while(x<x1) {if(d>0)d=d-2*dy; else {d=d-2*(dy-dx); x++; } y++; putpixel(x,y,color); } } void main() {int gdriver=DETECT,gmode; int x0,y0,x1,y1,color; initgraph(&gdriver,&gmode,"..\\BGI");
printf("data\n"); scanf("%d%d%d%d%d",&x0,&y0,&x1,&y1,&color); midpoint(x0,y0,x1,y1,color); getchar(); closegraph(); }