]> git.piffa.net Git - arduino/blob - books/ArduinoNextSteps-master/ArduinoNextSteps/sketch_06_02_factorial/sketch_06_02_factorial.ino
first commit
[arduino] / books / ArduinoNextSteps-master / ArduinoNextSteps / sketch_06_02_factorial / sketch_06_02_factorial.ino
1 // sketch_06_02_factorial
2
3 void setup()
4 {
5   Serial.begin(9600);
6   Serial.println(factorial(15));
7 }
8
9 void loop()
10 {
11 }
12
13 long factorial(long n)
14 {
15   if (n == 0) 
16   {
17     return 1;
18   }
19   else
20   {
21     return n * factorial(n - 1);
22   }
23 }