Advertisement
icatalin

24.9 din baza 2 in 10

Sep 24th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int n,cont=0,cop,nr=0,i,cif;
  10.     cout<<"Numarul in baza 2 este... ";
  11.     cin>>n;
  12.     cop=n;
  13.     while (cop)
  14.     {
  15.         cop=cop/10;
  16.         cont++;
  17.     }
  18.  
  19.     for (i=0;i<cont;i++)
  20.     {
  21.     cif=n%10;
  22.     n=n/10;
  23.     nr=nr+cif*pow(2,i);
  24.     }
  25.     cout<<nr;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement