Return 主函数的 powf 结果 C 编程
Return powf result to main function C Programming
我正在尝试创建一个单独的函数,该函数从主函数中获取参数 x 和 y,在 powf 中使用它,将其分配给变量 'result' 并将其输出到主函数。感谢任何帮助
#include <stdio.h>
#include <math.h>
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i <= y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", result);
return 0;
}
float mathPow(float x, float y){
result = powf(x,y);
return result;
}
我稍微修改了你的代码
float mathPow(float x, float y){
float result = powf(x,y);
return result;
}
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i <= y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", mathPow(x,y));
return 0;
}
如您所见,您没有在 main()
中调用函数 mathPow()
。
为了执行用户定义函数,您需要从您的main()
调用它们
这是整个程序的工作
#include <stdio.h>
#include <math.h>
float mathPow(float x, float y);
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i < y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", mathPow(x,y));
return 0;
}
float mathPow(float x, float y){
float result = powf(x,y);
return result;
}
我正在尝试创建一个单独的函数,该函数从主函数中获取参数 x 和 y,在 powf 中使用它,将其分配给变量 'result' 并将其输出到主函数。感谢任何帮助
#include <stdio.h>
#include <math.h>
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i <= y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", result);
return 0;
}
float mathPow(float x, float y){
result = powf(x,y);
return result;
}
我稍微修改了你的代码
float mathPow(float x, float y){
float result = powf(x,y);
return result;
}
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i <= y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", mathPow(x,y));
return 0;
}
如您所见,您没有在 main()
中调用函数 mathPow()
。
为了执行用户定义函数,您需要从您的main()
这是整个程序的工作
#include <stdio.h>
#include <math.h>
float mathPow(float x, float y);
int main() {
float x = 5.5;
float y = 3;
float total = 1;
int i;
for( i=0; i < y; i++ ) {
total = total * x;
}
printf("total = %.3f\n",total);
printf("Result of powf function is: %.3f\n", mathPow(x,y));
return 0;
}
float mathPow(float x, float y){
float result = powf(x,y);
return result;
}