满意答案
yj10377
推荐于 2017.11.24
采纳率:51% 等级:12
已帮助:10275人
没有问题,输出m=0.301030;n=0.004321;g=69.66
编译时会提示warning,主要原因有
1、int d=300000 过大,用长整形;
2、log()和log10()函数均是double型,double转成float会有截断误差,将float r=0.01,m,n,g;
中的float改成double就不会有warning了;
3、getch()函数未声明,头文件加入#include,就不会有warning了。
但warning不会影响运行结果。
c 里直接提供的是 以 e 为底的自然对数 log ,和 以 10 为底的常用对数 log10
其他对数写个函数就可以
#include
#include
double loga(double n, double base);
int main (void)
{
double a, b, c;
a = log(exp(1));
b = log10(10);
c = loga(100, 5);
printf("%lf %lf %lf", a, b, c);
}
double loga(double n, double base)
{ return log(n) / log(base);}
51分享举报