Templates are fun, especially when you start programming with them:
template <unsigned long n> struct Factorial {
static const unsigned long val = Factorial<n-1>::val * n;
};
template <> struct Factorial <0> {
static const unsigned long val = 1;
};
void setup() {
Serial.print(" 3! = "); Serial.print(Factorial<3>::val);
Serial.print(" 4! = "); Serial.print(Factorial<4>::val);
Serial.print(" 6! = "); Serial.print(Factorial<6>::val);
Serial.print("20! = "); Serial.print(Factorial<20>::val);
Serial.print("30! = "); Serial.print(Factorial<30>::val);
}
void loop(){}