这个程序错在哪里帮忙看下,万分感谢!!
可以运行,但是输出的值是一样的,请大神看看,万分感谢!#include<stdio.h>
#include<math.h>
#define PI 3.1415926
double d, lad, dltL,A0,dlty,sita;
int N;
struct complex
{
double read,imag;
};
complex fadd(complex fs1,complex fs2)
{
complex fs3;
fs3.read=fs1.read+fs2.read;
fs3.imag=fs1.imag+fs2.imag;
return fs3;
}
complex Aup(double pointx1,double pointx2,double pointy)
{
complex rst;
rst.read=0;
rst.imag=0;
lad=400;
lad*=1e-6;
double k=2*PI/lad;
N=(int)((pointx2-pointx1)/dltL);
for(int ii=0;ii<N;ii++)
{
complex lcpx;
lcpx.read=cos(k*dltL*ii*sin(sita));
lcpx.imag=sin(k*dltL*ii*sin(sita));
rst=fadd(rst,lcpx);
}
//rst=rst*A0;
rst.read=rst.read*A0;
rst.imag=rst.imag*A0;
return rst;
}
complex SUBY(double pointy)
{
double pointx1, pointx2;
complex y;
y.read=0;
y.imag=0;
int j;
double a[10]={0.00,0.03,0.07,0.10,0.13,0.15,0.18,0.20,0.23,0.25};
double b[10]={0.02,0.06,0.09,0.11,0.14,0.17,0.19,0.22,0.24,0.27};
for(j=0;j<10;j++)
{pointx1=a[j];
pointx2=b[j];
y.read+=Aup(pointx1,pointx2,pointy).read;
y.imag+=Aup(pointx1,pointx2,pointy).imag;
}
return y;
}
int main()
{
double pointy;
double pointy1=10.0;
double pointy2=50;
complex AP,IP;
int G;
printf("input a0:\n");
scanf("%lf",&A0);
printf("input dltL:\n");
scanf("%lf",&dltL);
printf("input d:\n");
scanf("%lf",&d);
printf("input dlty:\n");
scanf("%lf",&dlty);
G=(int)((pointy2-pointy1)/dlty);
printf("input sita(弧度制):\n");
scanf("%f",&sita);
for(int k=1;k<=G;k++)
{
pointy=10+dlty*k;
AP=SUBY(pointy);
IP.read=AP.read*AP.read;
IP.imag=AP.imag*AP.imag;
printf("IP=%.5f+i%.5f\n",IP.read,IP.imag);
}
return 0;
}