Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Recursive function won't compile
#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?

Report this thread to moderator Post Follow-up to this message
Old Post
bc1891@googlemail.com
04-03-08 03:07 AM


Re: Recursive function won't compile
On Apr 2, 5:23=A0pm, bc1...@googlemail.com wrote:
> #include <stdio.h>
> #include <stdlib.h>
>
> def RecursiveFact(n):
> =A0 =A0 if(n>1):
> =A0 =A0 =A0 =A0 return n*RecursiveFact(n-1)
> =A0 =A0 else:
> =A0 =A0 =A0 =A0 return 1
>
> fact =3D RecursiveFact(31)
> print fact
The output is 8222838654177922817725562880000000 and is correct. But
the "#include"s tell me you're a bit . Have you tried running
"python yourscript.py" (where "yourscript.py" is the filename you
saved the above program to)?

HTH,
Daniel

Report this thread to moderator Post Follow-up to this message
Old Post
ajaksu
04-03-08 03:07 AM


Re: Recursive function won't compile
In article <be71dc98-63c0-4a56-80e8-7d83b2d3e882@u36g2000prf.googlegroups.co
m>,
<bc1891@googlemail.com> wrote:

(Subject: Recursive function won't compile)

>#include <stdio.h>
>#include <stdlib.h>
>
>def RecursiveFact(n):

>......but yet it still gives the right answer. How is this possible?

Possibly because it gives the right answer in a different language than
it fails to compile in?


dave

--
Dave Vandervies                                     dj3vande at eskimo dot c
om
A violent rewrite could produce something worthwhile; as it is you need enou
gh
experience to not need the book to be able to read it.  Well, that makes sen
se
to me, anyhow.                                     --CBFalconer in comp.lang
.c

Report this thread to moderator Post Follow-up to this message
Old Post
dj3vande@csclub.uwaterloo.ca.invalid
04-03-08 03:07 AM


Re: Recursive function won't compile
bc1891@googlemail.com schrieb:
> #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?

Given that you obviously don't use python, but some weird cross-breed
beteween python and C - who are we to judge the semantics of that chimera?

Diez

Report this thread to moderator Post Follow-up to this message
Old Post
Diez B. Roggisch
04-03-08 03:07 AM


Re: Recursive function won't compile
On Apr 2, 5:00 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> bc1...@googlemail.com schrieb:
>
>
> 
> 
> 
> 
> 
>
> Given that you obviously don't use python, but some weird cross-breed
> beteween python and C - who are we to judge the semantics of that chimera?
>
> Diez

Seems like a bad belated April Fool's day joke to me.

George

Report this thread to moderator Post Follow-up to this message
Old Post
George Sakkis
04-03-08 03:07 AM


Re: Recursive function won't compile
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Robbie Hatley
04-03-08 03:07 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:43 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.