3. 题目:编一C程序,它能读如若干浮点数f1、f2、...fn(以-9999.0为结束标记,-9999.0不算在内)并输出在f2、f3、...fn这n-1个数中大于f1的数的个数、等于f1的数的个数和小于f1的数的个数。(注:可执行文件名为e4_3.exe)
程序设计:
#include "math.h"
main()
{float f[100],f1;
int n=0,i,i1=0,i2=0,i3=0;
printf("Please enter float:\n");
scanf("%f",&f1);
f[0]=f1;
while (abs(f[n]+9999.0)>=1e-4)
scanf("%f",&f[++n]);
for (i=1;i<=n-1;i++)
if (f[i]>f1) i1++;
else if (abs(f[i]-f1)<1e-4) i2++;
else i3++;
printf(">f1:%d\n",i1);
printf("=f1:%d\n",i2);
printf("<f1:%d\n",i3);
}