acobzew

arina-3-1

May 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. int convert(char *s){
  5.   int i,x,p;
  6.   i=x=0;
  7.   p=1;
  8.  
  9.   for(i=strlen(s)-1; i>=0; i--){
  10.     if((s[i]>='0')&&(s[i]<='9')){
  11.     x=x+(s[i]-'0')*p;}
  12.     else if(s[i]>='a'&&s[i]<='f'){
  13.     x=x+(s[i]-'a'+10)*p;}
  14.     else if(s[i]>='A'&&s[i]<='F'){
  15.     x=x+(s[i]-'A'+10)*p;}
  16.     p=p*16;
  17.   }
  18.   return x;
  19. }
  20.  
  21.  
  22. int main(){
  23.   char s[10];
  24.   scanf("%s",s);
  25.   printf("%d\n",convert(s));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment