Docsity

C++ Program to Convert Decimal to Octal Number, Exercises of Introduction to Computers

Partial preview of the text

Download C++ Program to Convert Decimal to Octal Number and more Exercises Introduction to Computers in PDF only on Docsity!

// C++ program to convert a decimal // number to octal number #include using namespace std; // function to convert decimal to octal void decToOctal( int n) { // array to store octal number int octalNum[100]; // counter for octal number array int i = 0; while (n != 0) { // storing remainder in octal arr octalNum[i] = n % 8; n = n / 8; i++; } // printing octal number array in rev for ( int j = i - 1; j >= 0; j--)

cout << octalNum[j]; } // Driver program to test above function int main() { int n = 33; decToOctal(n); return 0; }