Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int binary2octal(int n) {
- // your code here
- if(n/1000==0){
- if(n%1000==0) return 0;
- else if(n%1000==1) return 1;
- else if(n%1000==10) return 2;
- else if(n%1000==11) return 3;
- else if(n%1000==100) return 4;
- else if(n%1000==101) return 5;
- else if(n%1000==110) return 6;
- else return 7;
- }
- else return binary2octal(n/1000)*10+binary2octal(n%1000);
- }
- int main(){
- int n;
- while (cin >> n){
- cout << n << " is equivalent to " << binary2octal(n);
- cout << " in base 8" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement