3.题目:编一个C程序,它能读入一串浮点数(输入时,相邻的两个数用空格隔开,以0为结束标记,0不算在内),计算出其中绝对值最大者和最小者,并输出它们的原值。(注:可执行文件名为e8_3.exe)
程序设计:
#include "math.h"
main()
{float f,max,min;
int f1,f2;
printf("Please enter float number:\n");
scanf("%f",&f);
if (fabs(f-0.0)>1e-4)
{max=fabs(f);if (f>0.0) f1=0;else f1=1;
min=fabs(f);if (f>0.0) f2=0;else f2=1;
do {scanf("%f",&f);
if (fabs(f-0.0)<1e-4) break;
else {if (max<fabs(f)) {max=fabs(f);if (f>0.0) f1=0;else f1=1;}
if (min>fabs(f)) {min=fabs(f);if (f>0.0) f2=0;else f2=1;}
}
}
while (1);
}
if (f1==0) printf("abs max: %g\n",max);
else printf("abs max: %g\n",-max);
if (f2==0) printf("abs min: %g\n",min);
else printf("abs min: %g\n",-min);
}