|
发表于 2021-11-22 14:43:56
|
显示全部楼层
本帖最后由 jackz007 于 2021-11-22 14:52 编辑
- #include <stdio.h>
- unsigned long long foo(unsigned long long n)
- {
- return (n == 0) ? 1 : 2 * foo(n - 1) ;
- }
- int main(void)
- {
- unsigned long long i , x ;
- for(i = x = 0 ; i < 64 ; i ++) x += foo(i) ;
- printf("%I64u\n" , x) ;
- }
复制代码
编译、运行实况:
- D:\0002.Exercise\C>g++ -o x x.c
- D:\0002.Exercise\C>x
- 18446744073709551615
- D:\0002.Exercise\C>
复制代码
还有一个 "邪门" 的算法:
- #include <stdio.h>
- int main(void)
- {
- unsigned long long i , x ;
- for(i = x = 0 ; i < 64 ; i ++) x |= 1LL << i ;
- printf("%I64u\n" , x) ;
- }
复制代码
输出结果也是一模一样的。 |
|