From 3a2ce759d9ff45b99a209ac052e1047bdc3667c1 Mon Sep 17 00:00:00 2001 From: Laraib Memon <136256738+Laraib-Memon3@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:55:19 +0500 Subject: [PATCH] Update factorial_recursion.dart --- maths/factorial_recursion.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/maths/factorial_recursion.dart b/maths/factorial_recursion.dart index d620fcaa..6474ffb8 100644 --- a/maths/factorial_recursion.dart +++ b/maths/factorial_recursion.dart @@ -1,8 +1,9 @@ void main() { - var n = 5; - var fac = factorial(n); - print("$n! = $fac"); /* output: 5! = 120 */ + int n = 5; + int fac = factorial(n); + print("$n! = $fac"); // Output: 5! = 120 } -/* calculate factorial of n*/ -int factorial(var n) => n == 0 || n == 1 ? 1 : n * factorial(n - 1); +// Calculates the factorial of a given integer [n]. +// Returns 1 if [n] is 0 or 1; otherwise returns n * factorial(n - 1). +int factorial(int n) => n <= 1 ? 1 : n * factorial(n - 1);