Type Casting Explorer
C
Medium
3 views
Problem Description
Cast the float value 9.7 to a float in different ways: implicit, explicit, using floor, using cel. What will be the result in each case and why?
Official Solution
#include <stdio.h>
#include <math.h>
int main() {
float a = 9.7;
int x, y, z, w;
/* Implicit casting */
x = a;
/* Explicit casting */
y = (int)a;
/* Using floor() */
z = floor(a);
/* Using ceil() */
w = ceil(a);
printf("Original value: %.2fnn", a);
printf("Implicit casting result = %dn", x);
printf("Explicit casting result = %dn", y);
printf("Using floor() result = %dn", z);
printf("Using ceil() result = %dn", w);
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!