Public paste
none
By: j00 | Date: Nov 19 2007 22:21 | Format: C++ | Expires: never | Size: 778 B | Hits: 1208

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. string convert(int decimal);
  8. string dectobin(int decimal);
  9.  
  10. int main(int num)
  11. {
  12.    
  13.    int itemp;
  14.    cout << "enter i: ";
  15.    cin >> itemp;
  16.    cout<< "enter n: ";
  17.    cin>>num;
  18.    string y;
  19.    y = convert(num);
  20.    cout << "n" << y << "n";
  21.     system("PAUSE");
  22.     return EXIT_SUCCESS;
  23. }
  24.  
  25. string convert(int decimal)
  26. {
  27.        
  28.        return dectobin(decimal);
  29.        
  30. }
  31.  
  32. string dectobin(int decimal)
  33.  
  34.  
  35.     {
  36.     int r;
  37.     string x;
  38.     stringstream os;
  39.     if (decimal<=0)  
  40.  {
  41.         r = decimal % 2;
  42.         dectobin(decimal/2);
  43.         os <<r;
  44.         x.append(os.str());
  45.        
  46.          
  47.     }  
  48.     cout << x;
  49.             return x;
  50. }