cs107-lecture-examples

Example codes used during Harvard CS107 lectures
git clone https://git.0xfab.ch/cs107-lecture-examples.git
Log | Files | Refs | README | LICENSE

factorial.cpp (367B)


      1 // File       : factorial.cpp
      2 // Created    : Fri Nov 19 2021 03:33:24 PM (-0500)
      3 // Author     : Fabian Wermelinger
      4 // Description: Simple recursive function calls (factorial)
      5 // Copyright 2021 Harvard University. All Rights Reserved.
      6 
      7 int factorial(int x) // factorial
      8 {
      9     if (x > 1) {
     10         return x * factorial(x - 1); // recursive call
     11     }
     12     return 1;
     13 }