1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
2
Rep Power
0

#### recursive triangle

Program which enters two integer values , m and n , where m<=n.
Write a recursive function that prints a pattern of 2*(n-m+1) lines , where the first line contains m asterisks , the next line contains m+1 astrerisks , and so on up to line with n asterisks. Then the pattern is repeated backwards, going n back down to m.
- may not use loops in your recursive function !!

Example output :
triangle (3,5) will print this :

***
****
*****
****
***

Hint : Only one of the arguments changes in the recursive call .

2. here is a recursive solution in perl. im sure you'll be able to distinguish the relative parts:
Code:
```#!/usr/bin/perl

##      recursive example

recur(3, 5);

sub recur
{
(my \$m, \$n) = (@_);

if(\$n == \$m)
{
print "*" x \$m; print "\n";
return;
}
else
{
print "*" x \$m;         print "\n";
recur(++\$m, \$n);
print "*" x (\$m - 1);           print "\n";
}
}```
3. lol @ infamous41md
4. #### Re: recursive triangle

Originally posted by RoSe^MaReY
Program which enters two integer values , m and n , where m<=n. Write a recursive function that prints a pattern of 2*(n-m+1) lines, where the first line contains m asterisks , the next line contains m+1 astrerisks , and so on up to line with n asterisks. Then the pattern is repeated backwards, going n back down to m.
You mean 2*(n-m)+1 lines, unless the middle line is to be repeated twice?
5. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
2
Rep Power
0

thanks alot every body .. I solve it :)