✔ 最佳答案
#include<stdio.h>
int main()
{doubleave;
inti, I[10], s;
printf("Please enter 10 positive integers: ");
for (s=i=0; i<10; i++)
{scanf("%d", &I[i]);
if (I[i] < 0)i--;
s+= I[i];
}
i= ave= (double)s / 10;
if (ave - i > 0.5)i++;
printf("Sum: %d\tAverage: %f\tInteger nearest to average: %d\n", s, ave, i);
return 0;
}
2006-07-10 21:34:23 補充:
那是 double ave int i, I[10], s;網網把它接在一起了!!
2006-07-11 07:21:00 補充:
#include <stdio.h>#include <math.h>int main(){ double ave, d, t; int i, I[10], s;printf("Please enter 10 positive integers: ");for (s=i=0; i<10; i++){ scanf("%d", &I[i]); if (I[i] < 0)i--; s += I[i];}
2006-07-11 07:22:14 補充:
ave=(double)s/10;d=((unsigned)-1)/2;for(s=i=0;i<10;i++) if( (t=fabs(I[i]-ave)) < d) d=t,s=i;printf("Ave.: %f\t%dth item, %d, nearest to the ave.\n", ave, s, I[s]);return 0;}