Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 30th, 2003, 12:07 PM
 RoSe^MaReY
Junior Member

Join Date: Jun 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation 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
June 30th, 2003, 01:55 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
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
June 30th, 2003, 03:17 PM
 Onslaught
/(bb|[^b]{2})/

Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 5,163
Time spent in forums: 6 Days 1 h 34 m 20 sec
Reputation Power: 792
lol @ infamous41md

#4
June 30th, 2003, 09:44 PM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
Re: recursive triangle

Quote:
 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
July 1st, 2003, 05:35 PM
 RoSe^MaReY
Junior Member

Join Date: Jun 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0

thanks alot every body .. I solve it

 Viewing: Dev Shed Forums > Programming Languages > C Programming > recursive triangle