summaryrefslogtreecommitdiffstats
path: root/2
diff options
context:
space:
mode:
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