Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. cout << "1.Chcesz zamienic dziesietna na binarna?" << endl;
  8. cout<<"2. Chcesz zamienic binarna na dziesietna?"<<endl;
  9. short wybor;
  10. cin>>wybor;
  11. switch(wybor)
  12. {
  13. case 1:
  14. int x,i,wynik,r;
  15. i=0;
  16. wynik=0;
  17. do
  18. {
  19. cout<<"Podaj liczbe od 0 do 255"<<endl;
  20. cin>>x;
  21.  
  22. }
  23. while ((x<0) || (x>255) );
  24. while(x>0)
  25. {
  26. r=x%2;
  27. x=x/2;
  28. wynik=wynik+r*pow(10,i);
  29. i++;
  30.  
  31. }
  32. cout<<"Po zamianie liczba to: "<<wynik<<endl;
  33. break;
  34.  
  35. case 2:
  36. int y,z,wynikk,c;
  37. z=0;
  38. wynikk=0;
  39. cout<<"Podaj liczbe niedluzsza niz 8 znakow"<<endl;
  40. cin>>y;
  41. while(y>0)
  42. {
  43. r=y%10;
  44. y=y/10;
  45. wynikk=wynikk+r*pow(2,i);
  46. }
  47. cout<<"Po zamianie liczba to: "<<wynikk<<endl;
  48.  
  49. break;
  50.  
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement