notice that it's printing integer only
you are not returning anything when n==1 so whatever the printf returns will
be returns and see that printf returns the number of characters printed
the sequence of printing will be ---
in the opposite order

first f(1) will return 1
then f(2) prints 2*f(1) -->  *2* and returns no. characters printed i.e. 1
then f(3) prints 3*f(2) -->  *3* and returns no. characters printed i.e. 1
then f(4) prints 4*f(3) -->  *4* and returns no. characters printed i.e. 1
.
.
.
.
.
then f(9) prints 9*f(8) -->  *9* and returns no. characters printed i.e. 1
then f(10) prints 10*f(9) -->  *10* and returns no. characters printed i.e.
2
f(11) will print 11*2 --> *22*
.
.
.
.
.
f(20) will print 20*2 --> *40*

and hence the output is

234567891022242628303234363840

http://ideone.com/U4pJS

try to run it like machine will run you will get your doubt cleared

for clarification print newline("\n") after each printf u will get to
know what's happening
hope it helps !!





--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad




On Sat, Jul 30, 2011 at 3:04 PM, Abhishek Gupta <gupta.abh...@gmail.com>wrote:

> #include<stdio.h>
> int main()
> {
>     factorial(20);
>     return 0;
> }
>
> int factorial(int n)
> {
>     if(n==1)
>          return 1;
>    else
>         printf("%d",n*factorial(n-1));
> }
>
>
> its printing the result. i think it should not as sizeof(int) on linux
> fedora 15 compile:gcc is 4bytes.
> can anyone explain why?
>
> --
> Abhishek Gupta
> MCA
> NIT Calicut
> Kerela
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to