Public paste
asdfasdf
By: asdfasdf | Date: Nov 24 2007 23:40 | Format: C++ | Expires: never | Size: 814 B | Hits: 1643

  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.     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.          dectobin (num/base, base);
  37.          i = num % base;
  38.          string str;
  39.          stringstream out;
  40.          out << i;
  41.          str = out.str();
  42.          return dectobin (num, base);
  43.      
  44.  
  45.          
  46.          }
  47.  
  48.          
  49. }