10
Fonction récurrente
- #include <stdio.h>
- void printd( int );
- void printi( int i )
- {
- if ( i < 0 )
- {
- putchar( '-' );
- i = -i;
- }
- printd( i );
- }
- void printd( int i )
- {
- int d = i/10;
- if ( d )
- printd( d );
- putchar( (char)(i%10 + '0') );
- }
- main() {
- int x;
- x = 12345;
- putchar('x');
- putchar('=');
- printi( x );
- putchar('\n');
- x = -x;
- putchar('x');
- putchar('=');
- printi( x );
- putchar('\n');
- x = 0;
- putchar('x');
- putchar('=');
- printi( x );
- putchar('\n');
- }
$ gcc -o recur recur.c
$ ./recur
x=12345
x=-12345
x=0
Commentaires