Public paste
asdasdf
By: dafasd | Date: Nov 25 2007 00:09 | Format: C++ | Expires: never | Size: 1.01 KB | Hits: 1271

  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;  
  5.  
  6.  
  7. string dectobin(int num, int base);
  8. void convert(int n);
  9.  
  10. int main()
  11. {
  12.      
  13.     int decimalnum;
  14.     int base;
  15.      
  16.     base = 2;
  17.      
  18.     cout << "enter decimal: ";
  19.     cin >> decimalnum;
  20.     cout << endl;
  21.     cout<< "Decimal " << decimalnum << " = ";
  22.     cout<< dectobin(decimalnum, base);
  23.     cout << " binary" <<endl;
  24.      
  25.     system("PAUSE");
  26.     return 0;
  27.      
  28. }
  29.  
  30. string dectobin(int num, int base)
  31.  
  32. {
  33.        int i;
  34.       if( num > 0)  
  35.       {  
  36.            
  37.           i = num % base;
  38.           string str;
  39.           stringstream out;
  40.           out << i;
  41.           str = out.str();
  42.           return dectobin (num/base, base);
  43.        
  44.  
  45.            
  46.           }
  47.          if ( num =0)
  48.          {
  49.                
  50.           i = 0;
  51.           string str;
  52.           stringstream out;
  53.           out << i;
  54.           str = out.str();
  55.           return str;
  56.           }
  57.  
  58.          
  59. }