Decimal to octal

How to store it after divide it by 8

hi @kumarakash121005
U can use arrays or string to store it… then traverse it in reverse direction to print the ans…

u can refer this code -->

#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;

    string ans;
    while(n > 0){
        int rem = n % 8;
        n = n / 8;
        ans += to_string(rem);
    }

    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i];
    }
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.