Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. main(){
  4.   printf("Enter hex number");
  5.  
  6.   int result = getchar();
  7.  
  8.   result  = atoi(result);
  9.  
  10.   printf("the string is " + result);
  11.  
  12. }
  13.  
  14. int atoi(char s[]){
  15.   int i, n;
  16.   n = 0;
  17.   for (i = 0; s[i] != '\0'; ++i){
  18.     if (s[i] == 'a')
  19.       n+= 10;
  20.     else if (s[i] == 'b')
  21.       n+= 11;
  22.     else if (s[i] == 'c')
  23.       n+= 12;
  24.     else if (s[i] == 'd')
  25.       n+= 13;
  26.     else if (s[i] == 'e')
  27.       n+= 14;
  28.     else if (s[i] == 'f')
  29.       n+= 15;
  30.     else
  31.       n+=s[i];
  32.   }
  33.   return n;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement