C++ Program For Decimal To Octal Conversion Last Updated : 03 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The octal numbers are a base 8 number system that uses digits from 0-7 and the decimal numbers are a base 10 numbers system that uses 10 digits from 0-9 to represent any numeric value. In this article, we will learn how to write a C++ program to convert a given decimal number into an equivalent octal number. i.e. convert the number with base value 10 to base value 8. Algorithm to Convert Decimal Numbers to Octal in C++Create an array to store the octal representation.Run a loop till the number is not zero.Extract the remainder by taking the mod of the number by 8 and store the remainder in the array as an octal digit.Update the number by dividing it by 8 in each iteration.Print the array in reverse order.The below diagram shows an example of converting the decimal number 33 to an equivalent octal number. C++ Program to Convert Decimal Number To Octal Number C++ // C++ program to convert a decimal // number to octal number #include <iostream> 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 array octalNum[i] = n % 8; n = n / 8; i++; } // Printing octal number array in // reverse order for (int j = i - 1; j >= 0; j--) cout << octalNum[j]; } // Driver Code int main() { int n = 33; // Function Call decToOctal(n); return 0; } Output41ExplanationIf the given decimal number is 33. Step 1: Remainder when 33 is divided by 8 is 1. Therefore, arr[0] = 1. Step 2: Divide 33 by 8. The new number is 33/8 = 4. Step 3: Remainder, when 4 is divided by 8, is 4. Therefore, arr[1] = 4. Step 4: Divide 4 by 8. The new number is 4/8 = 0. Step 5: Since the number becomes = 0.Stop repeating steps and print the array in reverse order. Therefore, the equivalent octal number is 41. Complexity AnalysisTime Complexity: O(log N)Space Complexity: O(N), since creating an array to store octal numbers.Refer to the complete article Program for Decimal to Octal Conversion for more methods to convert Decimal numbers to Octal numbers. Comment More infoAdvertise with us Next Article C++ Program For Decimal To Octal Conversion K kartik Follow Improve Article Tags : C++ Programs C++ C++ Conversion Programs Practice Tags : CPP Similar Reads C++ Program For Octal To Decimal Conversion Given an octal number as input, we need to write a program to convert the given octal number into an equivalent decimal number. Examples: Input : 67Output: 55 Input : 512Output: 330 Input : 123Output: 83 1. Simple ApproachThe idea is to extract the digits of a given octal number starting from the ri 2 min read C++ Program For Hexadecimal To Decimal Conversion The hexadecimal numbers are base 16 numbers that use 16 symbols {0, 1, 2, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} to represent all digits. Here, (A, B, C, D, E, F) represents (10, 11, 12, 13, 14, 15). Decimal numbers are base 10 numbers with 10 symbols to represent all digits. In this article, we will l 3 min read C++ Program For Decimal To Hexadecimal Conversion In this article, we will learn to write a C++ program to convert a decimal number into an equivalent hexadecimal number. i.e. convert the number with base value 10 to base value 16. In the decimal system, we use ten digits (0 to 9) to represent a number, while in the hexadecimal system, we use sixte 3 min read C++ Program For Binary To Decimal Conversion The binary number system uses only two digits 0 and 1 to represent an integer and the Decimal number system uses ten digits 0 to 9 to represent a number. In this article, we will discuss the program for Binary to Decimal conversion in C++. Algorithm to Convert Binary Numbers to DecimalInitialize a v 4 min read C++ Program For Decimal To Binary Conversion Binary Numbers uses only 0 and 1 (base-2), while Decimal Number uses 0 to 9 (base-10). In this article, we will learn to implement a C++ program to convert Decimal numbers to Binary Numbers. The below diagram shows an example of converting the decimal number 17 to an equivalent binary number. Recomm 3 min read Like