Logic is okay, but the second putchar() call should be offset-ed by '0' character, not just 0-9 ...
I'd also avoid using hardcoded 48, not every compiler operates on ASCII literal (e.g, EBCDIC on some IBM mainframes). Best, -Lego On Thu, Oct 15, 2009 at 11:38 AM, Debanjan <[email protected]> wrote: > > On Oct 15, 10:45 am, umesh kewat <[email protected]> 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 < > [email protected]>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 > > > > -- Fear of the LORD is the beginning of knowledge (Proverbs 1:7) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
