printf ) )格式打印:
打印输出的变量类型为double,scanf (和printf )使用占位符%lf。
# include stdio.h # include math.hint main ({ double base; 双高度; double hypotenuse; scanf('%lf%lf )、base和height ); hypotenuse=sqrt(pow(base,2 ) pow ) height,2 ); printf('%lf(n ),hypotenuse base height; printf('%lf ',base * height/2 ); 返回0; }输出的数据带有小数点后6位。
printf )的输出结果保持两位小数,printf ) )的第一个参数的占位符(lf )变更为“%.2f”时,意味着取第二个参数(double型)的值输出。
# include stdio.h # include math.hint main ({ double base; 双高度; double hypotenuse; scanf('%lf%lf )、base和height ); hypotenuse=sqrt(pow(base,2 ) pow ) height,2 ); printf('%.2f(n ),hypotenuse base height ); printf('%.2f )、base * height/2 ); 返回0; }效果: