C复合体的数量和printf [英] C complex number and printf
本文介绍了C复合体的数量和printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印(使用的printf)复数?举例来说,如果我有这样的code:
的#include<&stdio.h中GT;
#包括LT&; complex.h>
INT主要(无效)
{
双复杂DC1 = 3 + 2 * I;
双复杂DC2 = 4 + 5 * I;
双重复杂的结果; 结果= DC1 + DC2;
的printf(??? \\ n,结果); 返回0;
}
..我应该用什么样的转换说明(或者别的什么),而不是???
解决方案
的printf(%F + I%F \\ N,creal(结果),cimag(结果));
我不相信有一个特定的格式说明的C99复杂类型。
How to print ( with printf ) complex number? For example, if I have this code:
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex dc1 = 3 + 2*I;
double complex dc2 = 4 + 5*I;
double complex result;
result = dc1 + dc2;
printf(" ??? \n", result);
return 0;
}
..what conversion specifiers ( or something else ) should I use instead "???"
解决方案
printf("%f + i%f\n", creal(result), cimag(result));
I don't believe there's a specific format specifier for the C99 complex type.
这篇关于C复合体的数量和printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文