Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- /// program
- using namespace std;
- void konw(int system, int liczba, int odstep) ///Odstep dodatkowy
- {
- int i=0; ///Jezeli i=0, to przed kazda liczba przekonwertowana bedzie 0
- ///np 2357(10)=4465(8) dla i=-1, ale 2357(10)=04465(8) dla i=0 (jeden dodatkowy bit)
- int A[1000]= {0};
- while (liczba!=0)
- {
- i++;
- A[i]=liczba%system;
- liczba=liczba/system;
- }
- while (i>=0)
- {
- cout<<A[i];
- ///Dodatkowe
- if (odstep!=0) ///bez tej linijki jezeli podamy odstep 0, program przestanie dzialac gdyz bedzie chcial wyliczyc reszte z dzielenia przez 0!!
- {
- if (i%odstep==0)
- {
- cout<<" ";
- }
- }
- ///Dodatkowe*
- i--;
- }
- }
- int main (void)
- {
- unsigned liczba=0,system=0,odstep=0;
- cout<<"Podaj system liczbowy <2;9>: "<<endl; cin>>system; ///ZAPYTANIE O SYSTEM
- if (system>9||system<2) ///JEZELI ZLY SYSTEM
- {
- cout<<"Blad: podano zly system.\nProgram zostanie zamkniety"<<endl;
- return 0;
- }
- cout<<"Podaj liczbe: "<<endl; cin>>liczba; ///ZAPYTANIE O LICZBE
- cout<<"Podaj odstep w wyniku (0-brak)"<<endl; cin>>odstep; ///Zapytanie o odstep
- cout<<"Liczba "<<liczba<<" w systemie o podstawie "<<system<<" to "<<endl;
- konw(system, liczba, odstep); ///Wywolanie funkcji konw
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement