aboutsummaryrefslogtreecommitdiff
path: root/2.3.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
commitc24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch)
tree460a005b6a3a9a967bd881bc2bf01e0becbe33cc /2.3.c
inital commit
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;
+}