C++ Convert from Decimal to Octal
###### Posted by Samath
Last Updated: January 05, 2017

This program will ask the user for a decimal number and convert the number into octal.

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char const *argv[])
{
int n;
int _dec;
int _oct = 0;
int dp = 1;

cout<<"Enter a number: ";
cin>>n;

_dec = n;
do {
_oct += (_dec % 8) * dp;
_dec /= 8;
dp *= 10;
} while( _dec != 0 );

cout << "The octal of " << n;
cout << " is " << _oct;

cin.get();
return 0;
}

###### Python to Convert Decimal to Binary, Octal and Hexadecimal
gideonna | Apr 13, 2016
###### Python Convert Decimal to Binary or Binary to Decimal
Samath | Jan 09, 2017
###### Convert Roman numerals to decimal using Java
Samath | Jan 17, 2024
###### Decimal to Binary in C++
Samath | Dec 26, 2014
###### SQL Display two digits after decimal point
SceDev | Feb 08, 2024
###### Converting Time To Decimal using C++
Samath | Jan 04, 2017
###### Binary to Decimal Conversion in C#
Samath | Jan 10, 2021
###### C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Samath | Apr 06, 2022
###### C++ program that prompts the user to input five decimal numbers, prints the five decimal numbers, converts each decimal number to the nearest integer, adds the five integers and prints the sum and average of the five integers.
Samath | Apr 06, 2022
###### JavaScript program that convert a string to spinal case
SceDev | Mar 28, 2024
###### How do you use the LOWER function to convert a string to lowercase?
LeoRobs | Jun 08, 2024
###### How do you use the TRY_CONVERT function to convert data types with error handling?
LeoRobs | Jun 29, 2024
###### How do you use the TRY_CONVERT function with different data types to convert values with error handling?
LeoRobs | Jul 28, 2024
###### How do you use the TRY_CONVERT function with different data types and styles to convert values with error handling in SQL Server?
AliceWk | Jul 14, 2024