Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What are the rules for converting float type into int type in C language?
What are the rules for converting float type into int type in C language?
# include & ltstdio.h & gt

//# include & lt; math.h & gt

int main()

{

int I;

int i2

int siz

float P[ 14]={0, 1,2,3, 1,5, 1,2,3,6. 1,500, 130,5,0 };

siz = sizeof(P); //Print out the number of bytes of array p..

printf("sizeof=%d\r\n ",siz);

for(I = 0; I< 14; i++)

{

printf("P[intp]=%d\r\n ",floor(P[I])); //Print out the value of each element of the p array and display it as int.

}

for(I2 = 0; i2 & lt 14; i2++)

{

printf("P[floatp]=%f\r\n ",P[I2]); //Print out the value of each element of the P array, and display it as floating point.

}

}

# include & ltstdio.h & gt

# include & ltmath.h & gt

int main()

{

int I;

int i2

int siz

float P[ 14]={0, 1,2,3, 1,5, 1,2,3,6. 1,500, 130,5,0 };

siz = sizeof(P); //Print out the number of bytes of array p..

printf("sizeof=%d\r\n ",siz);

for(I = 0; I< 14; i++)

{

printf("P[intp]=%d\r\n ",floor(P[I])); //Print out the value of each element of the p array and display it as int.

}

for(I2 = 0; i2 & lt 14; i2++)

{

printf("P[floatp]=%f\r\n ",P[I2]); //Print out the value of each element of the P array, and display it as floating point.

}

}

It seems that the result of running VC++6.0 is only useful for forced conversion. I wonder if there is anything wrong with the statement I wrote.