Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does c ++ language change the quotient of two integers into floating-point numbers?
How does c ++ language change the quotient of two integers into floating-point numbers?
int a=4,b = 3;

A/b//a is directly divided by b, and the value is1;

1.0*a/b// This is a floating-point type, and 1.0*a is a conversion type.

# include & ltstdio.h & gt

# include & ltstring.h & gt

# Define N 100?

int main()

{

int a=4,b = 3;

printf("a/b=%d a/b=%f\n ",a/b,a/b); //Can't directly control the output with the format character %f (the format character is inconsistent with the variable type, resulting in an output error)?

printf("a/b=%f\n ", 1.0 * a/b); //Both types can be cast?

printf("a/b=%f ",(float)a/b);

Returns 0;

}