如何用C表示复数? [英] how to represent complex number in C?
本文介绍了如何用C表示复数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何代表+ ib ??
a - 实际单位;
ib - imaginary unit;
How to represent a+ib ??
a - real unit;
ib - imaginary unit;
推荐答案
typedef struct Complex { double r; double i;} Complex;
并定义所有需要的功能,例如:
And define all the needed function, e.g.
Complex add(Complex x, Complex y) { Complex z; z.r = x.r+y.r; z.i=x.i+y.i; return z; }
Etc.
用法:
Etc.
Usage:
Complex a...; Complex b...; Complex c = add(a, b);
干杯
Andi
PS:或者您使用解决方案#2中建议的最新C标准的预定义< complex.h>
实现。
http://bit.ly/WcHPsm [ ^ ]
http://www.gnu.org/software/libc/manual/html_node/Complex-Numbers.html [ ^ ]
这篇关于如何用C表示复数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文