Putlong without function call.

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.

C++:
01 void printNum(unsigned long m)
02 {
03     if(m/10<1){
04         putchar(m+‘0’);
05         return;
06     }
07     else{
08         printNum(m/10);
09         putchar(m%10+‘0’);
10         return;
11     }
12 }
Advertisements
This entry was posted in Recursive. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s