Thanks Debanjan for intimating the bug in my code and Sorry i forget to add 48 in second putchar statement.
now rite code is #include<stdio.h> void print(unsigned long int n) { if(n>9) print(n/10); putchar('0'+(n%10)); } int main() { unsigned long n; scanf("%ld",&n); print(n); return 0; } On Fri, Oct 16, 2009 at 12:08 AM, Debanjan <debanjan4...@gmail.com> wrote: > > On Oct 15, 10:45 am, umesh kewat <umesh1...@gmail.com> wrote: > > Hi, > > Here is the code for problem... > > > > void print(unsigned long int n) > > { > > if(n<10) > > > > putchar(n+48); > > else > > { > > print(n/10); > > putchar(n%10); > > } > > > > } > > > > int main() > > { > > unsigned long int n; > > scanf("%ld",&n); > > print(n); > > return 0; > > > > } > > > > On Thu, Oct 15, 2009 at 9:33 AM, ankur aggarwal < > ankur.mast....@gmail.com>wrote: > > > > > 1. Given only putchar (no sprintf, itoa, etc.) write a routine > > > putlong that prints out an unsigned long in decimal. > > > > OOPS you code will print 1 when the input will be 10,100,100... > > -- > > Thanks & Regards > > > > Umesh kewat > > > > Sent from Hyderabad, AP, India > > > > -- Thanks & Regards Umesh kewat Sent from Hyderabad, AP, India --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---