digitalmars.D - Pizza Slicer
- Leo Custodio (20/20) Nov 20 2020 Implementation of the pizza slicer problem using recursion.
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