Challanges : decimal to octal

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

string octal = "";
while(n!=0){
    int r = n%8;
    n/=8;
    char c = r+'0';
    octal = c+octal;
}
cout << octal <<endl;

}
sir, please explain me this program, line by line in detail… i am not able to get it… we are not taught about arrays or strings yet, but in this challenge they are used… also why did we took octal in strings and then char c, why not in integer form… please explain me this program in detail

hey @Sheenagoyal21, below pic is procedure to convert octal to decimal

remainder that we get after this divison concatenated to string in the direction of arrow.

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.