在C中找到立方根
我试图找到该卷的立方根,但它无法正常工作。我认为浮点有问题,但不知道如何修复它。如您所见,Cube Root应该是3不是37
#include <stdio.h>
int main() {
int width;
int length;
int height;
int volume;
double volumes;
printf("write width ");
scanf("%d", &width);
printf("write length ");
scanf("%d", &length);
printf("write height ");
scanf("%d", &height);
volume = width * length * height;
printf("volume is %d \n", volume);
volumes = (double)pow((double)volume,1.0/ 3.0);
printf("cube root is %f \n", volumes);
return 0;
}
I am trying to find cube root of the volume and it does not work well. I think there is a problem with the floating point but do not know how to fix it. As you can see cube root should be 3 not 37
#include <stdio.h>
int main() {
int width;
int length;
int height;
int volume;
double volumes;
printf("write width ");
scanf("%d", &width);
printf("write length ");
scanf("%d", &length);
printf("write height ");
scanf("%d", &height);
volume = width * length * height;
printf("volume is %d \n", volume);
volumes = (double)pow((double)volume,1.0/ 3.0);
printf("cube root is %f \n", volumes);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 math.h 文件中使用 cbrt() 函数
you can use cbrt() function in math.h file