June 30th, 2003, 12:07 PM

recursive triangle
please help me .. i don't know how to write this program in C
Program which enters two integer values , m and n , where m<=n.
Write a recursive function that prints a pattern of 2*(nm+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 .
June 30th, 2003, 01:55 PM

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";
}
}
June 30th, 2003, 03:17 PM

June 30th, 2003, 09:44 PM

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*(nm+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*(nm)+1 lines, unless the middle line is to be repeated twice?

thanks alot every body .. I solve it :)