Date: Mon, 8 Feb 1999 11:12:06 +0530 (IST) From: "Raju K.V" X-Sender: rajukv AT tagore To: djgpp AT delorie DOT com Subject: Re: recursive factorial In-Reply-To: <002301be5318$9d1b86e0$461b2bc8@luis> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com instead of --passed try passed - 1 This works because parenthesis have higher precedence than *. so ur --passed gets executed first before the multiplication. For eg. passed = 5. then the return st --passed leads to passed = 4 raju On Mon, 8 Feb 1999, Luis Pistoia wrote: > 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: > > #include > #include > long int rcs_factorial(long int); > > main(){ > int num; > printf("Factorial of: "); > scanf("%d",&num); > printf(" %ld",rcs_factorial(num)); > } > > long int rcs_factorial(long int passed){ > if(passed <=1 ){ > printf("%d = ",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. > > Thanks. > Luis. > >