关于C语言的一道题原题:Write a program that requests a type double number and prints the value of the number cubed.Use a function of your own design to cube the value and print it.The main() program should pass the entered value to this fu
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 07:32:26
关于C语言的一道题原题:Write a program that requests a type double number and prints the value of the number cubed.Use a function of your own design to cube the value and print it.The main() program should pass the entered value to this fu
关于C语言的一道题
原题:Write a program that requests a type double number and prints the value of the number cubed.Use a function of your own design to cube the value and print it.The main() program should pass the entered value to this funtion.
我这样写的:
#include
double cube(double num);
int main(void)
{
double number;
printf("Please enter a type double number.\n");
scanf("%f",&number);
printf("The cube of %f is %f.\n",number,cube(number));
return 0;
}
double cube(double num)
{
return (num * num * num);
}
结果怎么输入结果都是The cube of 0.000000 is 0.000000.
然后把所有的double全都改成float以后就正常运行了
关于C语言的一道题原题:Write a program that requests a type double number and prints the value of the number cubed.Use a function of your own design to cube the value and print it.The main() program should pass the entered value to this fu
#include<stdio.h>double cube(double num);
int main(void){
double number;
printf("Please enter a type double number.\n");
scanf("%lf", &number); //float is %f,and the double is %lf
printf("The cube of %lf is %lf.\n", number, cube(number));
//float is %f,and the double is %lf
return 0;
}
double cube(double num){
return (num * num * num);
}