Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- int main()
- {
- string s;
- cout << "Podaj cene w systemie binarnym: ";
- cin >> s;
- string poPrzecinku = s.substr(s.length() - 2);
- string przedPrzecinkiem = s.substr(0, s.length() - 3);
- int czescCalkowita = 0;
- float czescUlamkowa = 0;
- int wykladnik = 0;
- for(int i = przedPrzecinkiem.length() - 1; i >= 0; i--)
- {
- if(przedPrzecinkiem[i] == '1')
- czescCalkowita += pow(2, wykladnik);
- wykladnik++;
- }
- wykladnik = -1;
- for(int i = poPrzecinku.length() - 1; i >= 0; i--)
- {
- if(poPrzecinku[i] == '1')
- czescUlamkowa += pow(2, wykladnik);
- wykladnik--;
- }
- float w = czescCalkowita + czescUlamkowa;
- cout << fixed << setprecision(2);
- cout << "Cena w systemie dziesietnym to: " << w;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement