Advertisement
Guest User

PD

a guest
Jan 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include<iostream>
  2. /// program
  3. using namespace std;
  4. void konw(int system, int liczba, int odstep) ///Odstep dodatkowy
  5. {
  6.     int i=0; ///Jezeli i=0, to przed kazda liczba przekonwertowana bedzie 0
  7.     ///np 2357(10)=4465(8) dla i=-1, ale 2357(10)=04465(8) dla i=0 (jeden dodatkowy bit)
  8.     int A[1000]= {0};
  9.     while (liczba!=0)
  10.     {
  11.         i++;
  12.         A[i]=liczba%system;
  13.         liczba=liczba/system;
  14.  
  15.     }
  16.     while (i>=0)
  17.     {
  18.         cout<<A[i];
  19.         ///Dodatkowe
  20.         if (odstep!=0) ///bez tej linijki jezeli podamy odstep 0, program przestanie dzialac gdyz bedzie chcial wyliczyc reszte z dzielenia przez 0!!
  21.         {
  22.             if (i%odstep==0)
  23.                 {
  24.                     cout<<" ";
  25.                 }
  26.         }
  27.         ///Dodatkowe*
  28.         i--;
  29.     }
  30. }
  31. int main (void)
  32. {
  33.     unsigned liczba=0,system=0,odstep=0;
  34.     cout<<"Podaj system liczbowy <2;9>: "<<endl; cin>>system; ///ZAPYTANIE O SYSTEM
  35.     if (system>9||system<2) ///JEZELI ZLY SYSTEM
  36.     {
  37.         cout<<"Blad: podano zly system.\nProgram zostanie zamkniety"<<endl;
  38.         return 0;
  39.     }
  40.     cout<<"Podaj liczbe: "<<endl; cin>>liczba; ///ZAPYTANIE O LICZBE
  41.     cout<<"Podaj odstep w wyniku (0-brak)"<<endl; cin>>odstep; ///Zapytanie o odstep
  42.     cout<<"Liczba "<<liczba<<" w systemie o podstawie "<<system<<" to "<<endl;
  43.     konw(system, liczba, odstep); ///Wywolanie funkcji konw
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement