7
The modulo operator and conditions
- #include <stdlib.h>
- #include <stdio.h>
- main() {
- int i1, i2;
- printf( "Enter 2 integers: " );
- if ( scanf("%d %d", &i1, &i2 ) == 2 )
- if ( i1 % i2 == 0 )
- printf("%d can be divided by %d.\n", i1, i2 );
- else
- printf("%d cannot be divided by %d.\n", i1, i2 );
- exit( 0 );
- }
$ gcc -o modulo modulo.c
$ ./modulo
Enter 2 integers: 20 7
20 cannot be divided by 7.
$ ./modulo
Enter 2 integers: -155 -5
-155 can be divided by -5.
Comments