C++编程基础练习16

来源:互联网 发布:淘宝找不到换购 编辑:程序博客网 时间:2024/06/05 00:22
/*
16: 第16题 请编写一个函数float fun(double h),
    函数的功能使对变量h中的值保留2位小数,
    并对第三位进行四舍五入(规定h中的值位正数)。
*/
#include <iostream>

using namespace std;

float fun(double h) ;

int main(int argc,char **argv){

    float h = 12.123456 ;
    fun(h) ;
    return 0 ;
}

float fun(double h){
    long t ;
    float s ;
    h = h*1000 ;
    t = (h+5)/10 ;
    s = t/100.0 ;
    
    return  s ;
}