在打印数字时,我试图在数字之前打印其符号。有没有办法在没有下面代码的注释部分中提到的实际 if...else 情况下做到这一点。
我试过获取数字的符号。但我不知道如何只打印标志。
#include<stdio.h>
#include<complex.h>
void main(){
double complex s = 3.14 + 5.14*I;
printf("\ns is: %f + %f i", creal(s), cimag(s));
double complex S = conj(s);
printf("\nConjugate of s is: %f + %f i", creal(S), cimag(S));
}
/*
printf("\nConjugate of s is: %f ", creal(S))
if cimag(S) > 0
printf("+ %f i", cimag(S))
else
printf("- %f i", abs(cimag(S)))
*/
Run Code Online (Sandbox Code Playgroud)
如果 S = 3.14 - 5.14*I,没有 if...else 条件,我希望得到这样的输出:
3.14 - 5.14 i
Run Code Online (Sandbox Code Playgroud)