Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C中的pow()工作不正常_C_Pow - Fatal编程技术网

C中的pow()工作不正常

C中的pow()工作不正常,c,pow,C,Pow,我不知道我是否误解了pow的概念,但我已经尝试了很多东西,不过,如果能在这里得到一些帮助,我会很感激为什么pow不起作用。 我试图计算体重指数,即体重指数=体重/(长度^2),我知道我可以这样做(长度*2),但我想学习pow函数 #include <stdio.h> #include <conio.h> #include <math.h> int main() { float langd1; float langd2; float

我不知道我是否误解了pow的概念,但我已经尝试了很多东西,不过,如果能在这里得到一些帮助,我会很感激为什么pow不起作用。 我试图计算体重指数,即体重指数=体重/(长度^2),我知道我可以这样做(长度*2),但我想学习pow函数

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

int main()


{
    float langd1;
    float langd2;
    float langd3;
    float langd4;
    float vikt1;
    float vikt2;
    float vikt3;
    float vikt4;

    {

        printf("Whats your weight?");
        scanf_s("%f", &vikt1);
        printf("Whats your weight?");
        scanf_s("%f", &vikt2);
        printf("Whats your weight?");
        scanf_s("%f", &vikt3);
        printf("Whats your weight?");
        scanf_s("%f", &vikt4);

        printf("Whats your lenght?");
        scanf_s("%f", &langd1);
        printf("Whats your lenght?");
        scanf_s("%f", &langd2);
        printf("Whats your lenght?");
        scanf_s("%f", &langd3);
        printf("Whats your lenght?");
        scanf_s("%f", &langd4);

        printf("User 1, your BMI is %f", vikt1 / pow(langd1));

        system("pause");


    }
    getchar();
    return(0);


}
#包括
#包括
#包括
int main()
{
浮动langd1;
浮动langd2;
浮动langd3;
浮动langd4;
浮动vikt1;
浮动vikt2;
浮动vikt3;
浮动t4;
{
printf(“你的体重是多少?”);
扫描频率(“%f”和“vikt1”);
printf(“你的体重是多少?”);
scanf_s(“%f”&vikt2);
printf(“你的体重是多少?”);
scanf_s(“%f”&vikt3);
printf(“你的体重是多少?”);
scanf_s(“%f”和vikt4);
printf(“你的长度是多少?”);
scanf_s(“%f”和langd1);
printf(“你的长度是多少?”);
scanf_s(“%f”&langd2);
printf(“你的长度是多少?”);
scanf_s(“%f”和langd3);
printf(“你的长度是多少?”);
scanf_s(“%f”和langd4);
printf(“用户1,您的体重指数为%f”,vikt1/pow(langd1));
系统(“暂停”);
}
getchar();
返回(0);
}
您应该使用
pow(langd1,2)

pow()
接受两个参数。第一个是基数,第二个是指数。它返回
(基本指数)

如果不给它第二个参数,它将调用未定义的行为edit:实际上它不会编译。我把它和可变参数混淆了


有关更多详细信息,请参见

pow()
接受两个参数,您给它一个。甚至不应该编译。
pow(x,y)
最肯定的是与
2*x
不一样,@Jongware除非
x==2
,但这是一个边缘情况。如果没有匹配的签名,它怎么可能编译?我永远不会使用pow(x,2)。x*x怎么了?