華爲機試-取近似值

#include<iostream>
using namespace std;

int main()
{
    float fInput;
    while (cin>>fInput)
    {
        int nTemp;
        nTemp = fInput * 10;
        int nHight = nTemp / 10;
        int nLow = nTemp % 10;
        if (nLow >= 5)
        {
            nHight++;
        }
        cout << nHight;
    }
    return 0;
}
發佈了58 篇原創文章 · 獲贊 46 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章