Advertisement
enkov

Преобразуване от десетична в произволна бройна система

Nov 14th, 2016
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int chislo, sistema, n;
  10.     int cifri[25];
  11.  
  12.     cout << "Chislo v osnova 10 = ";
  13.     cin >> chislo;
  14.  
  15.     cout << "V osnova = ";
  16.     cin >> sistema;
  17.  
  18.     n = 1;
  19.     while (chislo != 0)
  20.     {
  21.         cout << chislo << " ost. ";
  22.         cifri[n] = chislo % sistema;
  23.         cout << cifri[n] << endl;
  24.         chislo = chislo / sistema;
  25.         n = n + 1;
  26.     }
  27.  
  28.     // показваме резултата  - отзад напред, затова вадим 1
  29.     while (n > 1)
  30.     {
  31.         n = n - 1; //  връщаме с 1
  32.         if (cifri[n]<10)  cout << cifri[n] << " ";
  33.         // ако е над 10 - цифри A B C ... Z, 65 e кода на A
  34.         else cout << char('A' +cifri[n] - 10) << " ";
  35.     }
  36.     cout << endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement