www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pizza Slicer

Implementation of the pizza slicer problem using recursion.

import std.stdio;

void main()
{
	// number of cuts to apply
	int iCutMyPizzaIn = 11;
	
	// Let's cut my pizza
	int iPieces = CutMyPizza(iCutMyPizzaIn);
	
	writefln("Number of pieces left after %d cuts is %d.", 
iCutMyPizzaIn, iPieces);
}

int CutMyPizza(int iNumberOfCuts)
{
	if (iNumberOfCuts == 0)
		return 1;
	else
		return CutMyPizza(iNumberOfCuts - 1) + iNumberOfCuts;
}
Nov 20 2020