Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- long long convert (long long n)
- {
- int zbytek, decimal = 0, krok = 0;
- while (n!=0)
- {
- zbytek=n%10;
- n=n/10;
- decimal=decimal+(zbytek*pow(2,krok));
- ++krok;
- }
- return decimal;
- }
- int main()
- {
- long long n;
- cout << "Zadej bin: ";
- cin >> n;
- if (!cin.fail())
- {
- if (cin.peek() != '0' || cin.peek() !='1')
- {
- cout << convert(n) ;
- }
- else
- {
- cout << "hovno" << endl;
- }
- }
- else cout << "Spatny vstup." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement