cvs.gedasymbols.org/archives/browse.cgi   search  
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>&nbsp;</DIV>
<DIV><FONT size=3D2>#include &lt;stdio.h&gt;<BR>#include =
&lt;stdlib.h&gt;<BR>long=20
int rcs_factorial(long int);</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>main(){<BR>int num;<BR>printf(&quot;Factorial of:=20
&quot;);<BR>scanf(&quot;%d&quot;,&amp;num);<BR>printf(&quot;=20
%ld&quot;,rcs_factorial(num));<BR>}</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>long int rcs_factorial(long int passed){<BR>&nbsp; =
if(passed=20
&lt;=3D1 ){<BR>&nbsp;&nbsp;&nbsp; printf(&quot;%d =3D=20
&quot;,passed);<BR>&nbsp;&nbsp;&nbsp; return 1;<BR>&nbsp; }<BR>&nbsp;=20
else{<BR>&nbsp;&nbsp;&nbsp; printf(&quot;%d *=20
&quot;,passed);<BR>&nbsp;&nbsp;&nbsp; return passed *=20
rcs_factorial(--passed);<BR>&nbsp; }<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>&nbsp;</DIV>
<DIV><FONT size=3D2>Thanks.</FONT></DIV>
<DIV><FONT size=3D2>Luis.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></DIV></BODY></HTML>

------=_NextPart_000_0020_01BE52FF.5C0AC3A0--


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019