c语言ln函数复数怎么使用,如何使用C中的复数?

这段代码对你有帮助,而且相当不言自明:

#include       /* Standard Library of Input and Output */

#include     /* Standard Library of Complex Numbers */

int main() {

double complex z1 = 1.0 + 3.0 * I;

double complex z2 = 1.0 - 4.0 * I;

printf("Working with complex numbers:\n\v");

printf("Starting values: Z1 = %.2f + %.2fi\tZ2 = %.2f %+.2fi\n", creal(z1), cimag(z1), creal(z2), cimag(z2));

double complex sum = z1 + z2;

printf("The sum: Z1 + Z2 = %.2f %+.2fi\n", creal(sum), cimag(sum));

double complex difference = z1 - z2;

printf("The difference: Z1 - Z2 = %.2f %+.2fi\n", creal(difference), cimag(difference));

double complex product = z1 * z2;

printf("The product: Z1 x Z2 = %.2f %+.2fi\n", creal(product), cimag(product));

double complex quotient = z1 / z2;

printf("The quotient: Z1 / Z2 = %.2f %+.2fi\n", creal(quotient), cimag(quotient));

double complex conjugate = conj(z1);

printf("The conjugate of Z1 = %.2f %+.2fi\n", creal(conjugate), cimag(conjugate));

return 0;

}

有:

creal(z1):得到真正的部分(浮动crealf(z1),长双creall(z1))

cimag(z1):得到虚部(浮动cimagf(z1),长双cimagl(z1))

另外要记住很重要的一点,当使用复数的工作是一样的功能cos(),exp()并且sqrt()必须与他们复杂的形式,例如更换ccos(),cexp(),csqrt()。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值