3
#include <stdio.h>  
int main() {  
    //2+3j*98 ==> (2+294j)  
    printf("printf(\"%%i\",3j*58)\t%i\n",3j*58); // 0  
    printf("printf(\"%%f\",3j*58)\t%f\n",3j*58); // 0.00000000f  
    printf("printf(\"%%lf\",3j*58)\t%lf\n",3j*58); // 0.0000000  
    printf("printf(\"%%e\",3j*58)\t%e\n",3j*58); // 3.692273e-312  
    printf("printf(\"%%le\",3j*58)\t%le\n",3j*58); // 0.000000e+000  
    printf("printf(\"%%s\",3j*58)\t%s\n",3j*58); // (null)  
    return 0;  
}  

OUTPUT:

printf("%i",3j*58)  0  
printf("%f",3j*58)  0.000000  
printf("%lf",3j*58) 0.000000  
printf("%e",3j*58)  3.692273e-312  
printf("%le",3j*58) 0.000000e+000  

Just out of curiousity, how do you print an imaginary number in C. The 'normal' options don't seem to work.

Plakhoy
  • 1,846
  • 1
  • 18
  • 30
  • If you are a professional, you can try designing your own `"%z"` with help of `stdarg.h`. :-) – 0xF1 Sep 02 '13 at 11:03
  • How did you get this output? Where's `3j` defined? – luser droog Sep 02 '13 at 11:22
  • @luserdroog, does it need to have been defined somewhere. I thought `j` is the standard suffix for complex numbers. – Plakhoy Sep 02 '13 at 14:38
  • haha @nishant, that's a good one. I haven't the slightest clue on how to do that. The only thing I can do with `stdarg.h` is var-args. Care to give some pointers(no pun intended)? – Plakhoy Sep 02 '13 at 14:40
  • @Segfault That is the standard *mathematical* notation. C uses `*` for multiplication instead of juxtaposition. See [this question](http://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c). – luser droog Sep 02 '13 at 15:02

0 Answers0