156,663 views
20 votes
20 votes
Topic:

Recursion. Use recursion to display the pattern given above. No loops allowed.

See the picture for the pattern​

Topic: Recursion. Use recursion to display the pattern given above. No loops allowed-example-1
User Nakres
by
2.7k points

1 Answer

25 votes
25 votes

Answer:

const SIZE=8

function print(n, s) {

if (n > 0) {

process.stdout.write(s);

print(n-1, s);

}

}

function main(n=1) {

if (n<=SIZE) {

print(SIZE-n, " ");

print(n, "* ");

process.stdout.write("\\");

main(n+1);

}

}

main();

Step-by-step explanation:

Here is a solution in javascript. Note that it uses recursion multiple times to avoid loops.

User Ajay Padala
by
2.9k points