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

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0

    Unhappy 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*(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. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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";
            }
    }
  4. #3
  5. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    lol @ infamous41md
  6. #4
  7. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12

    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?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0

    Smile


    thanks alot every body .. I solve it :)

IMN logo majestic logo threadwatch logo seochat tools logo