请编一个函数float fun(double h),函数的功能是对变量h中的值保留两位小数,并对第三位进行四舍五入(规定h中的值为正数)

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include<stdio.h>
float fun(double h){
    long temp;
    temp = (h*1000 + 5)/10; 
    return (float) temp/100;
}
int main(){
    double h;
    float result;
    scanf("%lf",&h);
    result = fun(h);
    printf("k=%.2f \n",result);
    return 0;
}

你题目的解答代码如下:

#include<bits/stdc++.h>
using namespace std;
float fun(double h)
{
    return (int(h*100+0.5))/100.0;
}
int main()
{
    double h;
    cin >> h;
    cout << fun(h);
    return 0;
}

img

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img