Public paste
asdf1
By: asdf1 | Date: Nov 24 2007 21:57 | Format: C++ | Expires: never | Size: 689 B | Hits: 1436

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void dectobin(int num, int base);
  7. void convert(int n);
  8.  
  9. int main()
  10. {
  11.    
  12.     int decimalnum;
  13.     int base;
  14.    
  15.     base = 2;
  16.    
  17.     cout << "enter decimal: ";
  18.     cin >> decimalnum;
  19.     cout << endl;
  20.     cout<< "Decimal " << decimalnum << " = ";
  21.     dectobin(decimalnum, base);
  22.     cout << " binary" <<endl;
  23.    
  24.     system("PAUSE");
  25.     return 0;
  26.    
  27. }
  28.  
  29. void dectobin(int num, int base)
  30.  
  31. {
  32.      
  33.      if( num > 0)
  34.      {
  35.          dectobin (num/base, base);
  36.          cout << num % base;
  37.          
  38.          }
  39.          
  40.      if ( num < 0)
  41.      {
  42.  cout <<"supposed to be 2's compliment";
  43.          
  44. }