DropsBrowse Pastes
Login with GitHub

cmj已傻掉

March 1st, 2022Views: 16(0 unique)Plaintext
#include <stdio.h>
#include <math.h>
double fun(double, int);
int main(void)
{
    double x;
    int m;
    printf("请输入一个数以及其保留几位小数:\n");
    scanf("%lf %d", &x, &m);
    printf("%lf保留%d为小数为%lf\n", x, m, fun(double x, int m));
}
float fun(double x, int m)
{
    int z = int((x * pow(10, m + 1)) % 10) >= 5 ? (int((x * pow(10, m) % 10) + 1)) : int(x * pow(10, m) % 10);
    double m = (int)(x * pow(10, m - 1)) + (z * pow(0.1, 1));
    return m;
}