How do you write the algorithm to find the factorial of a number?

Answer

#! /usr/bin/env ruby

def fac(n)
return 1 if n<=1
return n * fac(n-1)
end

puts fac(gets.to_i)

Improve Answer Discuss the question "How do you write the algorithm to find the factorial of a number?" Watch Question

First answer by ID1456758152. Last edit by ID1456758152. Question popularity: 22 [recommend question]


Research your answer:

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Programming > How do you write the algorithm to find the factorial of a number?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
What is factorial number?  Short cut to find factorial?  Cprogramme of factorial of a number?  Write algorthim find factorial number?  Program to find the Factorial of a number?  C programme to find factorial of given no?  Algorithm to find factorial of given number?  What is a factorial number and how to find it?  Write a program to find factorial of a number?  Algorithm to find whether a no is prime or not?  Write an algorithm to find factorial of number?  What is the algorithm of a factorial of a number?  Program for finding factorial of the given number?  To find the factorial of a no using recursion in C?  That solves the factorial algorithm using step-form?  Write a progrmme input a number findout its factorial?  Write a function that returns the factorial of a number?  Algorithm for computing a factorial of a positive number?  How do you write a program to find the factorial of a number?  Write an algorith to find whether the number is prime or not?