473,799 Members | 2,934 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 1206
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
bc****@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

fact = "End of program"
print fact
......but yet it still gives the right answer. How is this possible?
Why not? What did you expect?

Hint:

The first two lines are comments to Python -- so are ignored.

The last two lines just print a string -- no problem there.

The recursive calculation is standard -- the extra set of parenthesis in
the if don't cause any problem.

So again please: Why are you surprised?

Gary Herron

Apr 2 '08 #5
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 #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
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
2433
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
7326
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
3389
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
1311
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
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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
10260
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...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
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
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2941
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.