程序在这里
#include <stdio.h>
#define
N
50
#define
M
11
void fun(int *a, int *b)
{
int i,j,c;
for(i=0;i<M;i++)
b[i]=0;
for(j=0;j<N;j++)
{if(a[j]>=100)
b[10]=a[j];
else
c=a[j]/10;}
switch(c)
{case 0: b[0]++;break;
case 1: b[1]++;break;
case 2: b[2]++;break;
case 3: b[3]++;break;
case 4: b[4]++;break;
case 5: b[5]++;break;
case 6: b[6]++;break;
case 7: b[7]++;break;
case 8: b[8]++;break;
case 9: b[9]++;break;}
}
double rnd()
{
static t=29, c=217, m=1024, r=0;
r=(r*t+c)%m;
return((double)r/m);
}
main()
{
int
age[N], i, d[M];
FILE *out ;
for(i=0;
i<N; i++)
age[i]=(int)(115*rnd());
printf("The original data :\n");
for(i=0; i<N; i++)
printf((i+1)%10==0?"%4d\n":"%4d",age[i]);
printf("\n\n");
fun( age,
d);
out=fopen ("out.dat","w");
for(i=0;i<10;i++)
{
printf("%4d---%4d
:
%4d\n", i*10, i*10+9, d[i]);
fprintf(out, "%4d---%4d
:
%4d\n", i*10, i*10+9, d[i]);
}
printf("
Over
100
:
%4d\n", d[10]);
fprintf(out, "
Over
100
:
%4d\n", d[10]);
fclose (out );
}