输出其图像
请多帮忙!
谢谢!
我只是做了点大概
#include <stdio.h>
#include <conio.h>
#include <Graphics.h>
main()
{
int gdriver=DETECT,gmode,errorcode;
int x,y,x0,y0,xmax,ymax;
int linecolor=3,axescolor=4,d=5;
double rate,k,b;
char mes[10];
system("cls");
printf("k=");
scanf("%lf",&k);
printf("b=");
scanf("%lf",&b);
system("cls");
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("initiate graph error:%s\nPress any key to exit:",grapherrormsg(errorcode));
getch();
exit(1);
}
xmax=getmaxx();
ymax=getmaxy();
x0=xmax/2;
y0=ymax/2;
setcolor(axescolor);
line(0,y0,xmax,y0);
line(xmax-d,y0-d,xmax,y0);
line(xmax-d,y0+d,xmax,y0);
rate=(k*480.0/640); /*其实rate=1更好看一些*/
for (x=0;x<xmax;x+=80)
{
sprintf(mes,"%d",x-x0-1);
line(x-1,y0-d,x-1,y0);
outtextxy(x-2*textwidth("W"),y0+textheight("W"),mes);
}
for (y=0;y<ymax;y+=80)
{
sprintf(mes,"%d",(int)((y0-y)*rate+1));
line(x0+d,y-1,x0,y-1);
outtextxy(x0-5*textwidth("W"),y,mes);
}
line(x0,0,x0,ymax);
line(x0-d,d,x0,0);
line(x0+d,d,x0,0);
setcolor(linecolor);
x=0;
y=y0-(k*(x-x0)+b)*rate;
moveto(x,y);
do
{
x++;
y=y0-(k*(x-x0)+b)*rate;
lineto(x,y);
}while(x<=xmax);
getch();
}