If you do not find what you're looking for, you can use more accurate words.
يمكن حساب عاملي عدد ما باستعمال خوارزميات الاستقراء. فلنكتب باستعمال لغة Scheme، القريبة من لغة Lisp، برنامجا استقرائيا يعطينا عاملي عدد صحيح :
(define fact (lambda (x) (if (= x 0) 1 (* x (fact (- x 1))))))
و هذا البرنامج السابق غير مفيد في حالة الاعداد الكبيرة.
و بنفس الطريقة في Caml :
let rec fact n = match n with | 0 -> 1 | _ -> n * fact(n-1) ;;
و بطريقة أخرى:
let fact n = let rec aux n r = match n with | 0 -> r | _ -> aux (n-1) (n*r) in aux n 1 ;;
و في لغة سي:
int factorielle_recursive(int n) { if (n == 0) return 1; return n * factorielle_recursive(n-1); }
و بطريقة أخرى:
int factorielle_iterative(int n) { int res; for (res = 1; n> 1; n--) res *= n; return res; }
و في لغة بايثون:
def factSimple(num) : if num== 0 : return 1 else : fact= 1 count= 1 while count<= num: fact*= count count+= 1 return fact print("5! = " +str(factSimple(5))) #on the screen : 5! = 120
وبطريقة ثانية:
def fact(num): if num==0: return 1 else: return num*factorial(num-1) print("5! = " +str(fact(5))) #on the screen : 5! = 120
وبطريقة ثالثة:
factLambda = lambda num : num>0 and num*fact(num-1) or 1 print("5! = " +str(factLambda(5))) #on the screen : 5! = 120
و في لغة جافاسكربت:
function fect(n){ let res; for (res = 1; n > 1; n--) res *= n; return res; }
وبطريقة اخرى:
function fact(n) { if (n == 0) return 1; else return n * fact(n - 1); }
هذه الدوال (البرامج) لا تمكننا من حساب عملي أعداد أكبر من 12 إذا كانت الاعداد الصحيحة محدودة بـ 32 بت، لأن النتيجة تتعدى المساحة المتوفرة.