diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
commit | c24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch) | |
tree | 460a005b6a3a9a967bd881bc2bf01e0becbe33cc /2.3.c |
inital commit
Diffstat (limited to '2.3.c')
-rw-r--r-- | 2.3.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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; +} |