TRIANGLE

C

coinjo

I need to write a program, which takes two inputs:
•a value n that represents the number of elements in the
longest row of a triangle.
•a character c to be printed in place of each element.
Your algorithm should produce an isosceles triangle of characters c.
For example,
for n=7 and c=’$’, the resulting triangle should be as follows:


$
$$$
$$$$$
$$$$$$$

Any hints please? It should only work for odd values of n.
 
V

Victor Bazarov

coinjo said:
I need to write a program, which takes two inputs:
??a value n that represents the number of elements in the
longest row of a triangle.
??a character c to be printed in place of each element.
Your algorithm should produce an isosceles triangle of characters c.
For example,
for n=7 and c='$', the resulting triangle should be as follows:


$
$$$
$$$$$
$$$$$$$

Any hints please? It should only work for odd values of n.

You input with

cin >>

you output with

cout <<

your program should have one function named 'main':

int main() {
...
}

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top