| 
 | 
 
< >本程序是求函数 p(x)=a*e^bx</P> 
< >#include<math.h></P> 
< >main(){</P> 
<P>         float sx[3],sy[2],x,y,b,A;                         int i,n;</P> 
<P>         sx[1]=sx[2]=sy[0]=sy[1]=0;printf("How many datas you have?\n");scanf("%d",&n);</P> 
<P>         if(n<1){printf("Input n ERROR!\n");exit(0);}sx[0]=n;</P> 
<P>for(i=0;i<n;i++){</P> 
<P>                   printf("Input \"x%d y%d\"!\n",i,i);          scanf("%f %f",&x,&y);</P> 
<P>                   sx[1]+=x;sx[2]+=x*x;sy[0]+=log(y);sy[1]+=x*log(y);</P> 
<P>                   printf("sx[1]=%f\t\tsx[2]=%f\t\t\n",sx[1],sx[2]);printf("sy[0]=%f\t\tsy[1]=%f\t\t\n",sy[0],sy[1]);</P> 
<P>         }</P> 
<P>         A=(sy[0]/sx[1]-sy[1]/sx[2])/(sx[0]/sx[1]-sx[1]/sx[2]);b=(sy[0]/sx[0]-sy[1]/sx[1])/(sx[1]/sx[0]-sx[2]/sx[1]);</P> 
<P>         printf("\n\nExpression:\nP(x)=%fe^(%f*x)\n\n",A,b);getch();</P> 
<P>} 
</P>[em01] |   
 
 
 
 |