为什么输896.4,结果是3.698

P5705 【深基2.例7】数字反转

Yarn_ball @ 2024-11-15 00:15:09

#include <iostream>
#include<iomanip>
#include <math.h>

using namespace std;

int main()
{

    double num;

    cin >> num;

    int a = num / 100;  //百位
    int b = (num - a * 100) / 10;  //十位
    int c = (int)num % 10;  //个位
    int d = ((num - (a * 100 + b * 10 + c)) * 10);    //0.1位

    cout << d + c * 0.1 + b * 0.01 + a * 0.001 << endl;

by _xguagua_Firefly_ @ 2024-11-15 07:13:41

丢精度了@Yarn_ball


|