简单C语言问题,高分悬赏!!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:10:24
做一个计算复数绝对值和偏角的源程序。

使用结构COMPLEX定义复数的实部和虚部,使用结构POLAR定义复数的绝对值和偏角。

要求如下:
1:使用结构COMPLEX输入复数Z。
2:使用COMPLEX,POLAR计算复数的绝对值和偏角。
3:使用POLAR输出绝对值和偏角。

(注:复数z = x + i y的绝对值是根号下x的平方加y的平方,其偏角是argtany/x。)

运行后要如下:

例1:

Input real part of z: 5
Input imaginary part of z: 4
absolute value of z: 6.403124
argument of z: 0.674741

例2:

Input real part of z: 1
Input imaginary part of z: 1
absolute value of z: 1.414214
argument of z: 0.785398

谢了。

#include <stdio.h>
#include <math.h>
struct COMPLEX{
float st_x; // 实部
float st_y; // 虚部
};
struct POLAR
{
float st_k; // 绝对值
float st_r; // 偏角
};
int main()
{
COMPLEX Z;
printf("Input real part of z:");
scanf("%f",&Z.st_x);
printf("Input imaginary part of z:");
scanf("%f",&Z.st_y);
POLAR K;
K.st_k=abs(sqrt(Z.st_x*Z.st_x+Z.st_y*Z.st_y));
K.st_r=atan(Z.st_y/Z.st_x);
printf("absolute value of z:%f\n",K.st_k);
printf("argument of z:%f\n",K.st_r);
return 1;
}