0 Replies - 66 Views - Last Post: 30 October 2008 - 09:28 AM

#1 Psionics   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 158
  • Joined: 06-September 08

Recursive Convert Number to Octal

Posted 30 October 2008 - 09:28 AM

Description: Use as a function, or in main if you wishRecursive function to print int into Octal
// Display a number in octal
void printOct(int n)
{
	if(n)
	{
		// Each octal digit is 3 bits
		printOct(n>>3);

		// The max value of 3 bits is 7
		cout << (n & 7);
	}

	// If I've got some code that needs to be done when we hit the exit condition, and only
	// once, use an else
	else
		cout << 0;
}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1