Skip to main content
4 of 4
Commonmark migration

Java 7, 49 48 bytes

int c(int a,int b){return-~a!=b?a*c(a+1,b):a*b;}

corsiKa's answer is exclusive, mine is inclusive (and slightly shorter by using recursion instead of a loop).

Explanation:

Try it here.

int c(int a,int b){  // Method with two integer parameters and integer return-type
  return-~a!=b?      //  If `a+1` is not equal to `b`
         a*c(a+1,b)  //   Return `a` multiplied by the recursive call with `a+1,b`
        :            //  Else:
         a*b;        //   Return `a*b`
}                    // End of method
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384