SHARE
TWEET

16 to 10 v.2

a guest Nov 9th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. using namespace std;
  5. int main()
  6. {
  7.     setlocale(0,"rus");
  8.     char st[10];
  9.     int i,k,p,s=0,w;
  10.     cout<<"Введите число в 16-ричной системе счисления: \n";
  11.     cin>>st;
  12.     p=strlen(st)-1;
  13.     for (i=0; st[i]!='\0'; i++)
  14.     {
  15.         switch (st[i])
  16.         {
  17.         case 'A': k=10; break;
  18.         case 'B': k=11; break;
  19.         case 'C': k=12; break;
  20.         case 'D': k=13; break;
  21.         case 'E': k=14; break;
  22.         case 'F': k=15; break;
  23.         case '1': k=1; break;
  24.         case '2': k=2; break;
  25.         case '3': k=3; break;
  26.         case '4': k=4; break;
  27.         case '5': k=5; break;
  28.         case '6': k=6; break;
  29.         case '7': k=7; break;
  30.         case '8': k=8; break;
  31.         case '9': k=9; break;
  32.         case '0': k=0; break;
  33.         }
  34.        s+=k*pow(16,p);
  35.         p--;
  36.     }
  37.     cout<<"Результат: ";
  38.     cout<<s;
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top