diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-24 21:44:34 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-24 21:44:34 +0800 |
| commit | 55dc65453a3c5d624d3d891c655bc5d572a59e3e (patch) | |
| tree | c5b88f040ffb9e50f4bd7d2d566c7317b0df8f87 /2 | |
| parent | acae19a3f4d4b52dd8b25edd8571d28ab18035ad (diff) | |
| download | k&r-exercises-55dc65453a3c5d624d3d891c655bc5d572a59e3e.tar.gz | |
2.1
Diffstat (limited to '2')
| -rw-r--r-- | 2/1.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ +#include <stdio.h> + +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 |
