no need to take care of negative numbers because given number is unsigned
long integer ......
apply simple algo :)

On Thu, Oct 15, 2009 at 1:07 PM, Siddharth S <[email protected]> wrote:

>
> void putlong(long n)
> {
>    if(n == 0) // special case
>    {
>       putchar('0');
>       return;
>    }
>    else
>    if(n < 0) // if number is negative, print "-" sign and continue as if it
> is a positive number
>      putchar('-'), n = -n;
>
>    int arr[30];
>    int arr_cnt = 0;
>    while(n)
>   {
>      arr[arr_cnt++] = n % 10; // split number into digits
>      n /= 10;
>   }
>    for(int i = arr_cnt-1; i>=0; i--) // print the digits (in reverse order)
>      putchar(arr[i]+'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.
>>
>>
>>
>
> >
>


-- 
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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to