From 4a74ade982db8ba36c65449a516e74a68494e40e Mon Sep 17 00:00:00 2001 From: Gamezardashvili George Date: Sun, 5 May 2024 03:25:02 +0530 Subject: [PATCH] Wrong factorial solution --- basics/tasks/factorial/include/solution.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/basics/tasks/factorial/include/solution.h b/basics/tasks/factorial/include/solution.h index 9dc41ec..840c74f 100644 --- a/basics/tasks/factorial/include/solution.h +++ b/basics/tasks/factorial/include/solution.h @@ -1,5 +1,12 @@ #pragma once int factorial(int number) { - return -1; // Replace this with your solution + int ans = 1; + if (number < 0) { + return -1; + } + for (int i = 1; i <= number; i++) { + ans *= i; + } + return ans; // Replace this with your solution }