部分答案参考了官方题解和网上的答案,仅供参考,可能也有部分bug未发现或解决。代码在gitee上面。
exercise2-1 编写一个程序以确定分别由 signed 及 unsigned 限定的 char、short、int 与 long 类型变量的取值范围。采用打印标准头文件中的相应值以及直接计算两种方式实现。后一种方法的实现较困难一些,因为要确定各种浮点类型的取值范围。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include <stdio.h> #include <limits.h> int main() { printf("Size of char %d\n", CHAR_BIT); printf("Size of char max %d\n", CHAR_MAX); printf("Size of char min %d\n", CHAR_MIN); printf("Size of short min %d\n", SHRT_MIN); printf("Size of short max %d\n", SHRT_MAX); printf("Size of int min %d\n", INT_MIN); printf("Size of int max %d\n", INT_MAX); printf("Size of long min %ld\n", LONG_MIN); printf("Size of long max %ld\n", LONG_MAX); printf("Size of unsigned char %u\n", UCHAR_MAX); printf("Size of unsigned short %u\n", USHRT_MAX); printf("Size of unsigned int %u\n", UINT_MAX); printf("Size of unsigned long %lu\n", ULONG_MAX); return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 Size of char 8 Size of char max 127 Size of char min -128 Size of short min -32768 Size of short max 32767 Size of int min -2147483648 Size of int max 2147483647 Size of long min -9223372036854775808 Size of long max 9223372036854775807 Size of unsigned char 255 Size of unsigned short 65535 Size of unsigned int 4294967295 Size of unsigned long 18446744073709551615 exercise2-2 在不使用运算符&&或||的条件下编写一个与上面的 for 循环语句等价的循环语句。...