百年孤独i 发表于 2020-8-12 21:21:19

练习题

#include <stdio.h>
#include <math.h>

int main()
{
        float p,r,n;
        r = 0.07;
        n = 10;
        p = pow(1+r,n);
        printf("%p = %f\n",p);
        return 0;
}
CTRL+F5后无error,但是显示的答案有误,怎么解决。应该输出的是p = 1.967151 调试结果显示是B515F7B2 = 0.000000
Press any key to continue
--------------------Configuration: 044 - Win32 Debug--------------------
Compiling...
044.c
E:\c++\Microsoft Visual Studio\MyProjects\044\044.c(7) : warning C4305: '=' : truncation from 'const double ' to 'float '
E:\c++\Microsoft Visual Studio\MyProjects\044\044.c(9) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data

044.obj - 0 error(s), 0 warning(s)

baige 发表于 2020-8-12 21:22:41

printf("p = %f\n", p);
多了个%号,去掉就好了

baige 发表于 2020-8-12 21:23:25

#include <stdio.h>
#include <math.h>

int main()
{
    float p, r, n;
    r = 0.07;
    n = 10;
    p = pow(1 + r, n);
    printf("p = %f\n", p);
    return 0;
}
页: [1]
查看完整版本: 练习题