5
Les instructions conditionnelles
- #include <stdlib.h>
- #include <stdio.h>
- int main() {
- int i1, i2;
- printf( "Enter 2 integers: " );
- if ( scanf("%d %d", &i1, &i2 ) == 2 )
- if ( i1 < i2 )
- printf("%d < %d\n", i1, i2 );
- else if ( i1 > i2 )
- printf("%d > %d\n", i1, i2 );
- else
- printf("%d = %d\n", i1, i2 );
- exit( 0 );
- }
$ gcc -o compare compare.c
$ ./compare
Enter 2 integers: 1 2
1 < 2
$ ./compare
Enter 2 integers: -1 -2
-1 > -2
$ ./compare
Enter 2 integers: 0 0
0 = 0
Commentaires