How to printf long long

前端 未结 4 1000
南旧
南旧 2020-11-30 10:48

I\'m doing a program that aproximate PI and i\'m trying to use long long, but it isn\'t working. Here is the code

#include
#include

        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 11:17

    %lld is the standard C99 way, but that doesn't work on the compiler that I'm using (mingw32-gcc v4.6.0). The way to do it on this compiler is: %I64d

    So try this:

    if(e%n==0)printf("%15I64d -> %1.16I64d\n",e, 4*pi);
    

    and

    scanf("%I64d", &n);
    

    The only way I know of for doing this in a completely portable way is to use the defines in .

    In your case, it would look like this:

    scanf("%"SCNd64"", &n);
    //...    
    if(e%n==0)printf("%15"PRId64" -> %1.16"PRId64"\n",e, 4*pi);
    

    It really is very ugly... but at least it is portable.

提交回复
热议问题