Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

write a program to print patter usign recursion in javascript

<script>
 
// JavaScript code to demonstrate star pattern
 
    // function to print a row
    function printn(num) {
        // base case
        if (num == 0)
            return;
        document.write("* ");
 
        // recursively calling printn()
        printn(num - 1);
    }
 
    // function to print the pattern
    function pattern(n , i) {
        // base case
        if (n == 0)
            return;
        printn(i);
        document.write("<br/>");
 
        // recursively calling pattern()
        pattern(n - 1, i + 1);
    }
 
    // Driver code
     
 
        var n = 5;
        pattern(n, 1);
 
// This code is contributed by aashish1995
 
</script>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #write #program #print #patter #usign #recursion #javascript
ADD COMMENT
Topic
Name
8+4 =