Decimal to Octal in C++

Here is a program in C++ to convert a decimal number to Octal:

```
#include <iostream>
using namespace std;

int main() {
int decimal, rem, i = 0, octal[100];

cout << "Enter decimal number: ";
cin >> decimal;

while (decimal > 0) {
rem = decimal % 8;
octal[i] = rem;
i++;
decimal = decimal / 8;
}

cout << "Octal equivalent: ";
for (int j = i - 1; j >= 0; j--)
cout << octal[j];

return 0;
}
```

Explanation:
- First, we declare variables `decimal`, `rem`, `i` and `octal`.
- `decimal` holds user input decimal number, `rem` holds the remainder of decimal/8, `i` counts the number of digits in the octal equivalent and `octal` is an array to hold the octal digits.
- We take input for `decimal` using `cin` statement.
- We use a while loop to convert decimal to octal using the following steps:
- Divide `decimal` by 8 and store the remainder in `rem`.
- Store the remainder `rem` in the `octal` array.
- Increment `i`.
- Update `decimal` by dividing it by 8.
- Repeat until `decimal` is greater than 0.
- After the while loop, we print the octal equivalent by iterating the `octal` array from the last digit to the first digit using a for loop.

Sample Output:
```
Enter decimal number: 123
Octal equivalent: 173
```