Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

c program to print triangle using 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: #program #print #triangle #recursion #javascript
ADD COMMENT
Topic
Name
3+2 =