Skip to content

Instantly share code, notes, and snippets.

@Arkar-Aung
Forked from trhura/calculator.erl
Last active August 29, 2015 14:11
Show Gist options
  • Save Arkar-Aung/f010430ee41dfb413d3d to your computer and use it in GitHub Desktop.
Save Arkar-Aung/f010430ee41dfb413d3d to your computer and use it in GitHub Desktop.
-module (calculator).
-export ([exponential/2, multiply/2]).
multiply(_, 0) -> 1;
multiply(Num, 1) -> Num;
multiply(Num, Exp) -> Num + multiply(Num, Exp-1).
exponential(_, 0) -> 1;
exponential(Base, 1) -> Base;
exponential(_, Exp) when(Exp < 0) -> throw("Bad argument");
exponential(Base, Exp) -> multiply(Base, exponential(Base, Exp-1)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment