Skip to content

Instantly share code, notes, and snippets.

@Davidslv
Created October 8, 2013 23:10
Show Gist options
  • Select an option

  • Save Davidslv/6893396 to your computer and use it in GitHub Desktop.

Select an option

Save Davidslv/6893396 to your computer and use it in GitHub Desktop.
factorial
# This are examples of how to implement a factorial in Ruby
def ft(n)
return 1 if n <= 1
n.downto(1).inject(:*)
end
def factorial(n)
return 1 if n <= 1
n * factorial(n - 1)
end
@Davidslv

Davidslv commented Oct 8, 2013

Copy link
Copy Markdown
Author
#include <stdio.h>

int main() {
  int c, n;
  long double fact = 1;

  printf("=>");
  scanf("%d", &n);

  for (c=1; c <= n; c++) {
    fact = fact * c;
  }

  printf("%Le\n", fact); /* this is still not the correct output */
  return 0;
}
./factorial
=>10001
inf

@Davidslv

Davidslv commented Feb 5, 2014

Copy link
Copy Markdown
Author

Read the one made with erlang here: https://gist.github.com/Davidslv/8832054

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment