summaryrefslogtreecommitdiffstats
path: root/2
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-24 21:44:34 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-24 21:44:34 +0800
commit55dc65453a3c5d624d3d891c655bc5d572a59e3e (patch)
treec5b88f040ffb9e50f4bd7d2d566c7317b0df8f87 /2
parentacae19a3f4d4b52dd8b25edd8571d28ab18035ad (diff)
downloadk&r-exercises-55dc65453a3c5d624d3d891c655bc5d572a59e3e.tar.gz
2.1
Diffstat (limited to '2')
-rw-r--r--2/1.c43
1 files changed, 43 insertions, 0 deletions
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 <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