问答题

下列给定程序中函数fun的功能是:把从主函数中输入的3个数,最大的数放在a中,中间的数放在b中,最小的数放在c中。
例如,若输入的数为:55 12 34,输出的结果应当是:a=55.0,b=34.0,c=12.0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
void fun(float *a, float *b, float *c)

/********** found********** /
float *k;
if(*a<*b)

k=*a;
*a=*b;
*b=k;

/********** found********** /
if(*a>*c)

k=*c;
*c=*a;
*a=k;

if(*b<*c)

k=*b;
*b=*c;
*c=k;


main()

float a, b, c;
printf("Input a b c: ");
scanf("% f% f% f", &a, &b, &c);
printf(“a=% 4.1 f, b=% 4.1 f, c=% 4.1 f\n\n", a, b, c);
fun(&a, &b, &c);
printf("a=% 4.1 f, b=% 4.1 f, c=% 4.1 f\n\n", a, b, c);

【参考答案】

(1)float k;
(2)if(*a< *c)