473,811 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(3 1)
print fact

fact = "End of program"
print fact
.......but yet it still gives the right answer. How is this possible?
Apr 2 '08 #1
6 1311
On Apr 2, 5:23*pm, bc1...@googlema il.com wrote:
#include <stdio.h>
#include <stdlib.h>

def RecursiveFact(n ):
* * if(n>1):
* * * * return n*RecursiveFact (n-1)
* * else:
* * * * return 1

fact = RecursiveFact(3 1)
print fact
The output is 822283865417792 281772556288000 0000 and is correct. But
the "#include"s tell me you're a bit confused. Have you tried running
"python yourscript.py" (where "yourscript .py" is the filename you
saved the above program to)?

HTH,
Daniel
Apr 2 '08 #2
In article <be************ *************** *******@u36g200 0prf.googlegrou ps.com>,
<bc****@googlem ail.comwrote:

(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 com
A violent rewrite could produce something worthwhile; as it is you need enough
experience to not need the book to be able to read it. Well, that makes sense
to me, anyhow. --CBFalconer in comp.lang.c
Apr 2 '08 #3
bc****@googlema il.com schrieb:
#include <stdio.h>
#include <stdlib.h>

def RecursiveFact(n ):
if(n>1):
return n*RecursiveFact (n-1)
else:
return 1

fact = RecursiveFact(3 1)
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
Apr 2 '08 #4
On Apr 2, 5:00 pm, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
bc1...@googlema il.com schrieb:
#include <stdio.h>
#include <stdlib.h>
def RecursiveFact(n ):
if(n>1):
return n*RecursiveFact (n-1)
else:
return 1
fact = RecursiveFact(3 1)
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
Seems like a bad belated April Fool's day joke to me.

George
Apr 2 '08 #5

"bc1891" wrote:
#include <stdio.h>
#include <stdlib.h>

def RecursiveFact(n ):
if(n>1):
return n*RecursiveFact (n-1)
else:
return 1

fact = RecursiveFact(3 1)
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.hAND <stdlib.h>
#use FORTRAN_RUNTIME _MODULE but compile_as(Cobo l)
#Incorporate{Pa scalInterpreter } 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",R ecursiveFact($A RGV[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*Recursive Fact(n-1):1;
}
int main (int argc, char ** argv)
{
printf("%d", RecursiveFact(a toi(argv[1])));
return 0;
}
--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
Apr 3 '08 #6
"Diez B. Roggisch" <de***@nospam.w eb.dewrites:
>#include <stdio.h>
#include <stdlib.h>

def RecursiveFact(n ):
if(n>1):
return n*RecursiveFact (n-1)
else:
return 1

fact = RecursiveFact(3 1)
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?
What do you mean? Aren't these:

#include <stdio.h.
#include <stdlib.h>

perfectly valid comments in Python?

Followups redirected.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 3 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2060
by: Amon Tse | last post by:
I have the following code which is unable to compile in VC6: #include <iostream> template<size_t target, size_t idx = 0> struct _Iterator { enum { value = (target == idx) ? idx : _Iterator<target, idx+1>::value
7
1180
by: avier | last post by:
Hello, I was reading the C++ codes and was confused by the following: double expect (double t, double x, double dt) const { return x + t*dt; }
7
567
by: Jon Slaughter | last post by:
#pragma once #include <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> class RDES_T {
4
2435
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2, opt1=opt1, opt2=opt2, opt3=opt3) return if type(arg2) is ListType:
64
7331
by: dmattis | last post by:
I am trying to write a recursive version of Power(x,n) that works by breaking n down into halves(where half of n=n/2), squaring Power(x,n/2), and multiplying by x again if n was odd, and to find a suitable base case to stop the recursion. Can someone give me an example of this? Thanks!
7
6132
by: Aloo | last post by:
Dear friends, If we declare a recursive function as 'inline' then does it actually convert to an iterative form during compilation ( the executable code is iterative)? Is it possible ? Please reply.
7
1880
by: sam_cit | last post by:
Hi Everyone, I have a function declared as inline and i was wondering as to how it would be expanded by the compiler sample(int x) { if (x>0) sample(--x); printf("%d",x); }
41
3393
by: Harry | last post by:
Hi all, 1)I need your help to solve a problem. I have a function whose prototype is int reclen(char *) This function has to find the length of the string passed to it.But the conditions are that no local variable or global variable should be used.I have to use recursive functions.
6
3909
by: Juha Nieminen | last post by:
Multiple inclusion of the same header file can cause the compilation to fail because of multiple definitions of the same type. That's why it's standard practice to write all headers like this: // SomeClass.hh #ifndef SOME_CLASS_HH #define SOME_CLASS_HH class SomeClass {
6
1207
by: bc1891 | last post by:
#include <stdio.h> #include <stdlib.h> def RecursiveFact(n): if(n>1): return n*RecursiveFact(n-1) else: return 1 fact = RecursiveFact(31)
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.