|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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*(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
Quote:
__________________
Jason Doucette / Xona.com™ - Programming Windows Errata Addendum "Discussion is an exchange of knowledge; argument is an exchange of ignorance." |
|
#5
|
|||
|
|||
|
thanks alot every body .. I solve it
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > recursive triangle |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|