Public paste
asdf
By: asdf | Date: Nov 25 2007 03:17 | Format: C++ | Expires: never | Size: 1.53 KB | Hits: 1257

  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;  
  5.  
  6.  
  7. void dectobin(int num, int base);
  8. void convert(int n);
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.     int decimalnum;
  15.     int base;
  16.  
  17.     base = 2;
  18.      
  19.     cout << "enter decimal: ";
  20.     cin >> decimalnum;
  21.     cout << endl;
  22.     cout<< "Decimal " << decimalnum << " = ";
  23.    
  24.    
  25.    
  26.     dectobin(decimalnum, base);
  27.     cout << " binary" <<endl;
  28.      
  29.     system("PAUSE");
  30.     return 0;
  31.      
  32. }
  33.  
  34. void convert(int n)
  35. {
  36.      
  37.      
  38.      
  39.      
  40.      
  41. }
  42.  
  43.  
  44. void dectobin(int num, int base)
  45.  
  46. {
  47.  
  48.        
  49.        int i;
  50.  
  51.        /*
  52.        i = num % base;
  53.       if( num/base > 0)  
  54.       {  
  55.           string test;
  56.           string str;
  57.           stringstream out;
  58.           out << i;
  59.           str = out.str();
  60.           test = dectobin ( num/base, base );
  61.           cout << "here is hello from " << num << " and my result is: >" << test << "< !" << endl;
  62.           return test;
  63.        
  64.  
  65.            
  66.           }
  67.          if ( num/base == 0)
  68.          {
  69.                
  70.           i = num % base;
  71.           string str;
  72.           stringstream out;
  73.           out << i;
  74.           str = out.str();
  75.           return str;
  76.           }
  77. */
  78.  
  79.      
  80.  
  81.      if( num > 0)
  82.      {
  83.          
  84.          dectobin (num/base, base);
  85.          i =  num % base;
  86.          string str;
  87.           stringstream out;
  88.           out << i;
  89.           str = out.str();
  90.          
  91.           cout << str;
  92.          
  93.          }
  94.        
  95. }