Thanks Aditi......I got it... On Mon, Jul 25, 2011 at 9:29 PM, aditi garg <[email protected]>wrote:
> in the frst pass its passed as f(20,1) n%2 =0 so else condition will be > returned ie. f(10,2) -1 > now in f(10,2) agn else and return will be f(5,4)-2 > now n%2=1 so return will be f(2,8) +4 > f(2,8) will be agn else and return will be f(1,16)-8 > now fr f(1,16) return will be f(0,32) +16 > and now at last return will be 0 > so the value will be -1-2+4-8+16=9 > > > On Mon, Jul 25, 2011 at 9:18 PM, Vijay Khandar <[email protected]>wrote: > >> #include<stdio.h> >> #include<conio.h> >> int f(int n,int k) >> { >> if (n==0) >> return 0; >> else >> if(n%2) >> return f(n/2,2*k)+k; >> else return f(n/2,2*k)-k; >> } >> int main() >> { >> clrscr(); >> printf("\n %d",f(20,1)); >> getch(); >> } >> >> O/p is 9.....Plz explai me how it is come........ >> >> >> Vijay......... >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > Aditi Garg > Undergraduate Student > Electronics & Communication Divison > NETAJI SUBHAS INSTITUTE OF TECHNOLOGY > Sector 3, Dwarka > New Delhi > > 9718388816 > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
