5
Convert a floating-point number to an integer
- #include <stdio.h>
- main() {
- const double pi = 22.0/7;
- printf( "pi = %f\n", pi );
- printf( "(int)pi = %d\n", (int)pi );
- }
$ gcc -o cast cast.c
$ ./cast
pi = 3.142857
(int)pi = 3
$ gcc -o cast cast.c
$ ./cast
pi = 3.142857
(int)pi = 3
Comments