0

I am trying to represent a very long number (i.e between 13 to 16 numerical digits) using C . long long does not seem to work as I am always getting an overflow problem.

I would appreciate it if someone can help me with this problem, thank you.

long long number = 123654123654123LL;
printf("%ull", number);
4

1 回答 1

6

格式说明符不正确,应该是%llu,类型number应该是unsigned long long

#include<stdio.h>

int main()
{
    unsigned long long number = 123654123654123LL;
    printf("%llu\n", number);

    return 0;
}

输出:

123654123654123

请参阅http://ideone.com/i7pLX

格式说明符后面%ull实际上是两个(ell) 字符。%ul

从 C99 标准的第5.2.4.2.1 节整数类型 <limits.h>的大小,最大值long longunsigned long long保证至少为:

LLONG_MAX +9223372036854775807 // 263 − 1
ULLONG_MAX 18446744073709551615 // 264 − 1

所以123654123654123舒适地在范围内。

于 2012-08-31T15:34:35.320 回答