Natural number sum in the recrusion using in javascript

technical talkiess
0
Natural number sum in the recrusion using in javascript


<script>
       
        function sumnaturalnumber(n){
            if(n > 0){
                return n + sumnaturalnumber(n - 1);
            }else{
                return n;
            }
        }

        let n1 = parseInt(prompt("Enter the natural no which you want to sum"));
      let result = sumnaturalnumber(n1);
      console.log(result);

    </script> 

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)