c2.0程序运算数值过大,如何解决?
#include "math.h"
#define a 9.96
#define x1 2.52
#define x2 4.54
#define E 324
#define p 3.14
main()
{
double operation(double s);
double x;
printf("please write down s=");
scanf("%d",&x);
printf("result=%E\n",operation(x));
getch();
}
double operation(double s)
{
int n;
double y1,y2,D1,D2,Y;
y1=0;
y2=0;
for(n=1;n<100;n++)
{
D1=1/a*sin(n*p*x1/a)*sin(n*p*x2/a);
D1=n*p*s/a/sqrt(E);
D1=D1*sin(D2);
D2=D1*cos(D2);
y1=(float)y1+D1;
y2=(float)y2+D2;
}
Y=(double)(pow(y1,2)+pow(y2,2));
return(Y);
}