Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int binary(int dec) {
- int bin = 0;
- int rem;
- for(int i = 1; dec; i *= 10) {
- rem = dec % 2;
- dec /= 2;
- bin += rem * i;
- }
- return bin;
- }
- int main() {
- int n;
- cin >> n;
- cout << "Binary: " << binary(n) << endl;
- cout << "Octal: " << oct << n << endl;
- cout << "Hexa-decimal: " << hex << n << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement