#include <stdio.h>
#include <math.h>
float math(int, int, int, int, int, float, float, float);
main() {
int a, b, c, d, e;
float sum, avg, sd;
printf("Enter Five Integers->");
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
math(a, b, c, d, e, sum, avg, sd);
printf("Sum=%.2f\nAverage=%.2f\nStandard Deviation=%.2f", sum, avg, sd);
}
float math(int a, int b, int c, int d, int e, float sum, float avg, float sd) {
sum = a + b + c + d + e;
avg = (sum)/5;
sd = pow(
((pow(a - avg, 2) + pow(b - avg, 2) + pow(c - avg, 2) + pow(d - avg, 2),
pow(e - avg, 2))/
5),
0.5);
return sum, avg, sd;
}
我的程序总是返回0.00的答案。任何人都可以解释我的代码有什么问题吗?为什么我的代码返回0.00?
请正确缩进您的代码。阅读逗号操作符所做的事情,您不会分配返回值;变量是按值传递的,因此在函数中改变它们根本没有帮助。 –
当您逐步完成代码时,调试器会告诉您什么? –
您的'数学'函数并不会返回您认为它的功能(请阅读[逗号运算符](http://en.cppreference.com/w/c/language/operator_other#Comma_operator))。你可能需要[找到一个好的初学者书](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)并阅读更多关于函数以及参数和返回值价值观工作。 –