63

Recur

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void printd( int );
  6.  
  7. void printi( int i )
  8. {
  9.     if ( i < 0 )
  10.     {
  11.         cout.put( '-' );
  12.         i = -i;
  13.     }
  14.     printd( i );
  15. }
  16.  
  17. void printd( int i )
  18. {
  19.     int d = i/10;
  20.     if ( d )
  21.         printd( d );
  22.     cout.put( char(i%10 + '0') );
  23. }
  24.  
  25. int main()
  26. {
  27.     int x;
  28.  
  29.     x = 12345;
  30.     cout << x << "=";
  31.     printi( x );
  32.     cout << endl;
  33.  
  34.     x = -x;
  35.     cout << x << "=";
  36.     printi( x );
  37.     cout << endl;
  38.  
  39.     x = 0;
  40.     cout << x << "=";
  41.     printi( x );
  42.     cout << endl;
  43. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].