
By: asdf | Date: Nov 25 2007 03:17 | Format: C++ | Expires: never | Size: 1.53 KB | Hits: 1237
- #include <iostream>
- #include <sstream>
- using namespace std;
- void dectobin(int num, int base);
- void convert(int n);
- int main()
- {
- int decimalnum;
- int base;
- base = 2;
- cout << "enter decimal: ";
- cin >> decimalnum;
- cout << endl;
- cout<< "Decimal " << decimalnum << " = ";
- dectobin(decimalnum, base);
- cout << " binary" <<endl;
- system("PAUSE");
- return 0;
- }
- void convert(int n)
- {
- }
- void dectobin(int num, int base)
- {
- int i;
- /*
- i = num % base;
- if( num/base > 0)
- {
- string test;
- string str;
- stringstream out;
- out << i;
- str = out.str();
- test = dectobin ( num/base, base );
- cout << "here is hello from " << num << " and my result is: >" << test << "< !" << endl;
- return test;
- }
- if ( num/base == 0)
- {
- i = num % base;
- string str;
- stringstream out;
- out << i;
- str = out.str();
- return str;
- }
- */
- if( num > 0)
- {
- dectobin (num/base, base);
- i = num % base;
- string str;
- stringstream out;
- out << i;
- str = out.str();
- cout << str;
- }
- }
Latest pastes
2 hours ago
1 days ago
1 days ago
2 days ago
3 days ago