From 55dc65453a3c5d624d3d891c655bc5d572a59e3e Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 24 Nov 2021 21:44:34 +0800 Subject: 2.1 --- 2/1.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 2/1.c diff --git a/2/1.c b/2/1.c new file mode 100644 index 0000000..5cb0239 --- /dev/null +++ b/2/1.c @@ -0,0 +1,43 @@ +#include + +void printu(int size); +void prints(int size); + +/* prints the max ranges of char, short, int and long */ +int main(int argc, char *argv[]) { + printf("char: "); + prints(sizeof(char)); + + printf("unsigned char: "); + printu(sizeof(unsigned char)); + + printf("short: "); + prints(sizeof(short)); + + printf("unsigned short: "); + printu(sizeof(unsigned short)); + + printf("int: "); + prints(sizeof(int)); + + printf("unsigned int: "); + printu(sizeof(unsigned int)); + + printf("long: "); + prints(sizeof(long)); + + printf("unsigned long: "); + prints(sizeof(unsigned long)); + + return 0; +} + +void printu(int size) { + int bits = 8 * size; + printf("0 to %ld\n", (1L << (bits - 1)) + ((1L << (bits - 1)) - 1)); +} + +void prints(int size) { + int bits = 8 * size; + printf("%ld to %ld\n", -(1L << (bits - 1)), (1L << (bits - 1)) - 1); +} \ No newline at end of file -- cgit v1.2.3