Mail Archives: djgpp/1999/02/07/23:09:50
Message-ID: | <002301be5318$9d1b86e0$461b2bc8@luis>
|
From: | "Luis Pistoia" <lu5gpl AT arnet DOT com DOT ar>
|
To: | <djgpp AT delorie DOT com>
|
Subject: | recursive factorial
|
Date: | Mon, 8 Feb 1999 01:07:12 -0300
|
MIME-Version: | 1.0
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Mailer: | Microsoft Outlook Express 4.72.3110.5
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3
|
Reply-To: | djgpp AT delorie DOT com
|
This is a multi-part message in MIME format.
------=_NextPart_000_0020_01BE52FF.5C0AC3A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Could anyone give me a little help?
I'm trying to use recursive programming for getting a factorial of a =
number. The source I've made is:
=20
#include <stdio.h>
#include <stdlib.h>
long int rcs_factorial(long int);
=20
main(){
int num;
printf("Factorial of: ");
scanf("%d",&num);
printf(" %ld",rcs_factorial(num));
}
=20
long int rcs_factorial(long int passed){
if(passed <=3D1 ){
printf("%d =3D ",passed);
return 1;
}
else{
printf("%d * ",passed);
return passed * rcs_factorial(--passed);
}
}
But it doesn't work. It does the rigth number of calls to rcs_factorial =
but fails at doing the first multiplication.
=20
Thanks.
Luis.
=20
------=_NextPart_000_0020_01BE52FF.5C0AC3A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>
<DIV><FONT size=3D2>Could anyone give me a little help?</FONT></DIV>
<DIV><FONT size=3D2>I'm trying to use recursive programming for getting =
a=20
factorial of a number. The source I've made is:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>#include <stdio.h><BR>#include =
<stdlib.h><BR>long=20
int rcs_factorial(long int);</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>main(){<BR>int num;<BR>printf("Factorial of:=20
");<BR>scanf("%d",&num);<BR>printf("=20
%ld",rcs_factorial(num));<BR>}</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>long int rcs_factorial(long int passed){<BR> =
if(passed=20
<=3D1 ){<BR> printf("%d =3D=20
",passed);<BR> return 1;<BR> }<BR> =20
else{<BR> printf("%d *=20
",passed);<BR> return passed *=20
rcs_factorial(--passed);<BR> }<BR>}<BR></FONT></DIV>
<DIV><FONT size=3D2>But it doesn't work. It does the rigth number of =
calls to=20
rcs_factorial but fails at doing the first multiplication.</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Thanks.</FONT></DIV>
<DIV><FONT size=3D2>Luis.</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV></DIV></BODY></HTML>
------=_NextPart_000_0020_01BE52FF.5C0AC3A0--
- Raw text -