From e6537b8ea337276b9c0edb5edd76a92da565f2ad Mon Sep 17 00:00:00 2001 From: Shubham Bhati <112773220+Shubh2-0@users.noreply.github.com> Date: Wed, 1 Feb 2023 04:32:45 +0530 Subject: [PATCH] Create Ways to zero.js --- .../JavaScript/src/recursion/Ways to zero.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 algorithms/JavaScript/src/recursion/Ways to zero.js diff --git a/algorithms/JavaScript/src/recursion/Ways to zero.js b/algorithms/JavaScript/src/recursion/Ways to zero.js new file mode 100644 index 00000000..7539afe3 --- /dev/null +++ b/algorithms/JavaScript/src/recursion/Ways to zero.js @@ -0,0 +1,20 @@ +// Description + +// Given an integer N. In how many ways you can subtract numbers 1, 2, and, 5 from N such that value of N reduces to 0. + + + +function fun(num){ +if(num<0){ + return 0; +} +if(num==0){ + return 1 +} +return fun(num-1)+fun(num-2)+fun(num-5); +} + + + +let num = 4 +console.log(fun(num))