Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recursive function printTriangle ( ) that takes two integers as parameters and prints a triangle of asterisks based on those parameters. The first

Write a recursive function printTriangle() that takes two integers as parameters
and prints a triangle of asterisks based on those parameters. The first integer represents the
maximum number of asterisks to be printed in the last row of the triangle pattern seen in the
examples below. The second integer represents the indentation used for the last line of the
pattern. The first parameter may be zero or negative, in which case nothing should be printed.
You should assume that the second parameter is non-negative (>=0). There is no relationship
assumed between the two parameters. You are allowed to use string multiplication (e.g. c * n for a
character c and an integer n) and concatenation, but no other string functions are allowed. The
following shows several sample runs of the function:File Edit Shell Debug Options Windows Help
) printTriangle (10,0)
t.
t+t t
|t+t+-t+-
tot
printTriangle (5,5)
t+t
t.t
printTriangle (4,5)
tt
ttt
printTriangle (7,0)
t+t
t+t+t
t+-t+-t+-t
printTriangle (0,0)
printTriangle (-3,5)
>
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

What determines who must file a tax return?

Answered: 1 week ago

Question

Explain what makes the structure of the human language so unique

Answered: 1 week ago

Question

2. How do they influence my actions?

Answered: 1 week ago