Facebook
From Red Cassowary, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 199
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int liczba,i,j,tab[10],p;
  8.     cout << "Zamiana liczby dziesietnej na binarna!" << endl;
  9.     cout <<"Podaj liczbe do zamiany"<<endl;
  10.     cin>>liczba;
  11.     cout << "Podaj podstawe nowego systemu od 2 do 9"<<endl;
  12.     cin>>p;
  13.  
  14.     for (i=0;i<10;i++)
  15.         tab[i]=0;
  16.     i=0;
  17.     while(liczba>0)
  18.     {
  19.         tab[i]=liczba%p;
  20.         liczba=liczba/p;
  21.         i++;
  22.     }
  23.     for (j=i-1;j>=0;j--)
  24.  
  25. if (tab[j]==10) cout <<"A";
  26.     else if (tab[j]==11) cout <<"B"<<" ";
  27.     else if (tab[j]==12) cout <<"C"<<" ";
  28.     else if (tab[j]==13) cout <<"D"<<" ";
  29.     else if (tab[j]==14) cout <<"E"<<" ";
  30.     else if (tab[j]==15) cout <<"F"<" ";
  31.     else cout<<tab[j]<<" ";
  32.  
  33.  
  34.  
  35.  
  36.          return 0;
  37. }
  38.