#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? 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
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 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 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
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
"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" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
{
|
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:
|
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!
|
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.
| |
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);
}
|
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.
|
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
{
|
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)
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |