39.2k views
1 vote
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

1 Answer

3 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 Kingdango
by
5.1k points