Decimal To Octal

This algorithm converts decimal numbers to octal numbers.



									/*****Please include following header files*****/
// string
/***********************************************/

/*****Please use following namespaces*****/
// std
/*****************************************/

static string DecimalToOctal(int dec) {
	if (dec < 1) return "0";

	string octStr = "";

	while (dec > 0)
	{
		octStr = octStr.insert(0, to_string(dec % 8));
		dec /= 8;
	}

	return octStr;
}
								


Example

									int data = 667887;
string value = DecimalToOctal(data);
								


Output

									2430357