C语言四舍五入保留两位小数的程序怎么写?

2024-12-27 03:46:50
推荐回答(1个)
回答1:

#include  

double fun ( float  h )

{ return  (long)( h * 100 + 0.5  )/ 100.0;
}main( )
{  

float  a;
printf ("Enter  a:  "); scanf ( "%f", &a );
printf ( "The original data is :   " );
printf ( "%f \n\n", a );
printf ( "The result :  %f\n", fun ( a ) );

}