麻烦哪位大虾帮我解释一下其中几行代码
//代码作用为做出f=x^2的图形#include<stdio.h>
double m(double x)
{
return (x*x);
}
double a,b,setp;
//定义画图函数graph
void graph(double (*f)(),double a,double b,double step)
{
double fmax,fmin,res,i,scale;
int x;
fmax=fmin=(*f)(a);
//寻找最大值最小值
for(i=a;i<=b;i+=step)
{
res=(*f)(i);
fmax=(fmax<res)?res:fmax;
fmin=(fmin<res)?fmin:res;
}
printf("max=%lf\nmin=%lf\n",fmax,fmin);
scale=60./(fmax-fmin);
//求此处scale作用解释?
for(i=a;i<=b;i+=step)
{
res=(*f)(i);
for(x=1;x<(int)(res*scale);x++)
putchar(' ');
//此处for语句循环有什么作用?
printf("*\n");
}
}
void main()
{
graph(m,-1.0,1.0,0.1);
}