我是一个完全的编程初学者,我有一个任务要做,它几乎只是从一个复数中找到 R 和 theta,并根据它所在的象限使用 if 语句采取适当的行动。
IE; 在象限 1 和 2 中使用计算的 theta,当在象限 3 中从计算的 theta 中减去 180 度时,当在象限 4 中时,在计算的 theta 中添加 180 度
我真的很难找到 theta,当我输入 1+1j 时,我得到了正确的 R,但不正确的 theta。我正在使用 theta = atan(b/a);
#include <stdio.h>
int main()
{
float a, b, r, j, theta, thetaquadrant3, thetaquadrant4, convert ;
j = -1;
b = b*-1;
thetaquadrant3 = theta - 180;
thetaquadrant4 = theta + 180;
printf ("Please enter intput A and B in the form of a+bj\n");
printf ("Input A:");
scanf ("%f" , &a);
printf ("Input B:");
scanf ("%f" , &b);
if ((a>=0.0) && (b >= 0.0))
{
//take no action as the calculated angle is in quadrant 1
r = sqrt (pow(a, 2) + pow(b , 2));
printf ("R=%f\n\n" , r);
theta = atan(b/a);
printf ("Theta=%f\n\n", theta );
}
if ((a<=-0.0) && (b >= 0.0))
{
//take no action as the calculated angle is in quadrant 2
r = sqrt (pow(a, 2) + pow(b , 2));
printf ("R=%f\n\n" , r);
theta = atan(b/a);
printf ("Theta=%f\n\n", theta );
}
if ((a<=-0.0) && (b <= -0.0))
{
//Quadant 3
r = sqrt (pow(a, 2) + pow(b , 2));
printf ("R=%f\n\n" , r);
theta = atan(b/a);
printf ("Theta=%f\n\n", thetaquadrant3 );
}
if ((a>=0.0) && (b <= -0.0))
{
//Quadrant 4
r = sqrt (pow(a, 2) + pow(b , 2));
printf ("R=%f\n\n" , r);
theta = atan(b/a);
printf ("Theta=%f\n\n", thetaquadrant4 );
}
// Converting back to rectangular Co-ordinates
convert = r*cos(theta) + j*r*sin (theta);
printf ("Corresponds to%f\n\n" , convert);
return 0;
}
任何帮助是极大的赞赏