Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- cout << "1.Chcesz zamienic dziesietna na binarna?" << endl;
- cout<<"2. Chcesz zamienic binarna na dziesietna?"<<endl;
- short wybor;
- cin>>wybor;
- switch(wybor)
- {
- case 1:
- int x,i,wynik,r;
- i=0;
- wynik=0;
- do
- {
- cout<<"Podaj liczbe od 0 do 255"<<endl;
- cin>>x;
- }
- while ((x<0) || (x>255) );
- while(x>0)
- {
- r=x%2;
- x=x/2;
- wynik=wynik+r*pow(10,i);
- i++;
- }
- cout<<"Po zamianie liczba to: "<<wynik<<endl;
- break;
- case 2:
- int y,z,wynikk,c;
- z=0;
- wynikk=0;
- cout<<"Podaj liczbe niedluzsza niz 8 znakow"<<endl;
- cin>>y;
- while(y>0)
- {
- r=y%10;
- y=y/10;
- wynikk=wynikk+r*pow(2,i);
- }
- cout<<"Po zamianie liczba to: "<<wynikk<<endl;
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement