aboutsummaryrefslogtreecommitdiff
path: root/2.3.c
diff options
context:
space:
mode:
Diffstat (limited to '2.3.c')
-rw-r--r--2.3.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/2.3.c b/2.3.c
new file mode 100644
index 0000000..21b0040
--- /dev/null
+++ b/2.3.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+int
+main(void)
+{
+ char input;
+ int num;
+
+ num = 0;
+
+ while ((input = getchar()) != EOF) {
+
+ if (input == '0') {
+ if ((input = getchar()) == 'x' || input == 'X')
+ continue;
+ else
+ input = '0';
+ }
+
+ if (!((input >= '0' && input <= '9') || (input >= 'a' && input <= 'f') || (input >= 'A' && input <= 'F')))
+ continue;
+ else if (input >= '0' && input <= '9')
+ num = num * 16 + input - '0';
+ else if (input >= 'a' && input <= 'f')
+ num = num * 16 + 10 + input - 'a';
+ else if (input >= 'A' && input <= 'F')
+ num = num * 16 + 10 + input - 'A';
+
+ }
+
+ printf("\n%d\n", num);
+
+ return 0;
+}