Re: Recursive function won't compile

Discussion in 'Perl' started by Robbie Hatley, Apr 3, 2008.

  1. "bc1891" wrote:

    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > def RecursiveFact(n):
    > if(n>1):
    > return n*RecursiveFact(n-1)
    > else:
    > return 1
    >
    > fact = RecursiveFact(31)
    > print fact
    >
    > fact = "End of program"
    > print fact
    >
    > ......but yet it still gives the right answer. How is this possible?



    No, no, no. Write that in Haskell instead, like this:


    #Switch<C++RTTI>(ON)
    #include <stdio.h> AND <stdlib.h>
    #use FORTRAN_RUNTIME_MODULE but compile_as(Cobol)
    #Incorporate{PascalInterpreter} but run_as(Haskell)
    use strict;
    use warnings;
    sub RecursiveFact
    {
    my $n=shift;
    if ($n > 1)
    {
    return $n * RecursiveFact($n-1);
    }
    else
    {
    return 1;
    }
    }
    printf("%d\n",RecursiveFact($ARGV[0]));


    Yep, that there Haskell program should solve these C++
    problems you've been having with that Oberon program of yours,
    by injecting a bit of Perlescence.


    Or just write it in Fortran and be done with it:


    /* This is a really lovely Fortran program. */
    #include <stdio.h>
    #include <stdlib.h>
    int RecursiveFact (int n)
    {
    return n>1?n*RecursiveFact(n-1):1;
    }
    int main (int argc, char ** argv)
    {
    printf("%d", RecursiveFact(atoi(argv[1])));
    return 0;
    }


    --
    Cheers,
    Robbie Hatley
    lonewolf aatt well dott com
    www dott well dott com slant user slant lonewolf slant
    Robbie Hatley, Apr 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. judith
    Replies:
    4
    Views:
    1,068
  2. Nagaraj
    Replies:
    1
    Views:
    842
    Lionel B
    Mar 1, 2007
  3. n00m
    Replies:
    12
    Views:
    1,104
  4. Recursive function won't compile

    , Apr 2, 2008, in forum: C Programming
    Replies:
    5
    Views:
    347
    Keith Thompson
    Apr 3, 2008
  5. Replies:
    6
    Views:
    300
    Keith Thompson
    Apr 3, 2008
Loading...

Share This Page