. This question needs to be more
focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅关注editing this post的一个问题。
3个月前关闭。
Improve this question
当您从键盘输入三个数字时,将计算并显示它们的平均值,并显示输入值本身以及从输入值中减去平均值的结果(带+号,最多三位小数)。程序来做。
规范:
在键盘上输入并显示结果。
主面。输入的值是浮点数。 在函数ave3()中计算平均值。这个
函数从主要方面接受三个数据作为参数,
计算它们的平均值,并将结果返回
值。 从输入数据中减去平均值的操作
在功能sub3()中执行。该功能接收
有关来自主要方面和平均值的三个数据的信息
先前计算为参数的值,然后减去平均值
从这三个数据中的每一个。此函数没有返回值,并且
主端输出在函数中更改的三个值
他们是。
源代码#include <stdio.h>
double ave3 (double, double, double);
double subave3 (double *, double *, double *);
int main ()
{
double a, b, c, ave;
printf ("Please enter three values: \ n");
scanf ("% lf% lf% lf", & a, & b, & c);
ave = ave3 (& a, & b, & c); / * Function call * /
printf ("Average:% .3f \ n", ave);
printf ("Original data:% + .3f% + .3f% + .3f \ n", a, b, c);
subave3 (double * x, double * y, double * z);
printf ("Data after average deduction:% + .3f% + .3f% + .3f \ n", a, b, c);
return 0;
}
/ * A function that calculates the average. It also subtracts the average value from the data. * /
double subave3 (double x, double y, double z)
{
x-= ave; / * Subtract the average from each data * /
y-= ave;
z-= ave;
a = x;
b = y;
c = z;
return a, b, c;
}
double ave3 (double x, double y, double z) {
ave = (* x + * y + * z) / 3.0;
return ave;
}
错误prog01.c: In function ‘main’:
prog01.c: 13: 14: error: incompatible type for argument 1 of ‘ave3’
13 | ave = ave3 (& a, & b, & c); / * Function call * /
| ^ ~
| |
| double *
prog01.c: 3:13: note: expected ‘double’ but argument is of type ‘double *’
3 | double ave3 (double, double, double);
| ^ ~~~~~
prog01.c: 13: 18: error: incompatible type for argument 2 of ‘ave3’
13 | ave = ave3 (& a, & b, & c); / * Function call * /
| ^ ~
| |
| double *
prog01.c: 3:21: note: expected ‘double’ but argument is of type ‘double *’
3 | double ave3 (double, double, double);
| ^ ~~~~~
prog01.c: 13: 22: error: incompatible type for argument 3 of ‘ave3’
13 | ave = ave3 (& a, & b, & c); / * Function call * /
| ^ ~
| |
| double *
prog01.c: 3:29: note: expected ‘double’ but argument is of type ‘double *’
3 | double ave3 (double, double, double);
| ^ ~~~~~
prog01.c: 18:11: error: expected expression before ‘double’
18 | subave3 (double * x, double * y, double * z);
| ^ ~~~~~
prog01.c: 18: 3: error: too few arguments to function ‘subave3’
18 | subave3 (double * x, double * y, double * z);
| ^ ~~~~~~
prog01.c: 4: 8: note: declared here
4 | double subave3 (double *, double *, double *);
| ^ ~~~~~~
prog01.c: At top level:
prog01.c: 26: 8: error: conflicting types for ‘subave3’
26 | double subave3 (double x, double y, double z)
| ^ ~~~~~~
prog01.c: 4: 8: note: previous declaration of ‘subave3’ was here
4 | double subave3 (double *, double *, double *);
| ^ ~~~~~~
prog01.c: In function ‘subave3’:
prog01.c: 28: 8: error: ‘ave’ undeclared (first use in this function); did you mean ‘ave3’?
28 | x-= ave; / * Subtract the average from each data * /
| ^ ~~
| ave3
prog01.c: 28: 8: note: each undeclared identifier is reported only once for each function it appears in
prog01.c: 32: 3: error: ‘a’ undeclared (first use in this function)
32 | a = x;
| ^
prog01.c: 33: 3: error: ‘b’ undeclared (first use in this function)
33 | b = y;
| ^
prog01.c: 34: 3: error: ‘c’ undeclared (first use in this function)
34 | c = z;
| ^
prog01.c: In function ‘ave3’:
prog01.c: 40: 3: error: ‘ave’ undeclared (first use in this function); did you mean ‘ave3’?
40 | ave = (* x * y * z) / 3.0;
| ^ ~~
| ave3
prog01.c: 40:10: error: invalid type argument of unary ‘*’ (have ‘double’)
40 | ave = (* x * y * z) / 3.0;
| ^ ~
prog01.c: 40: 15: error: invalid type argument of unary ‘*’ (have ‘double’)
40 | ave = (* x * y * z) / 3.0;
| ^ ~
prog01.c: 40: 20: error: invalid type argument of unary ‘*’ (have ‘double’)
40 | ave = (* x * y * z) / 3.0;
| ^ ~