Advertisement
fojtasd

Untitled

Oct 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. long long convert (long long n)
  7. {
  8. int zbytek, decimal = 0, krok = 0;
  9. while (n!=0)
  10. {
  11. zbytek=n%10;
  12. n=n/10;
  13. decimal=decimal+(zbytek*pow(2,krok));
  14. ++krok;
  15. }
  16. return decimal;
  17. }
  18.  
  19.  
  20.  
  21. int main()
  22. {
  23. long long n;
  24. cout << "Zadej bin: ";
  25. cin >> n;
  26. if (!cin.fail())
  27. {
  28. if (cin.peek() != '0' || cin.peek() !='1')
  29. {
  30. cout << convert(n) ;
  31. }
  32. else
  33. {
  34. cout << "hovno" << endl;
  35. }
  36. }
  37. else cout << "Spatny vstup." << endl;
  38.  
  39. return 0;
  40.  
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement