详细代码如下:
#include <stdio.h>
# define N 50
# define M 11
void fun(int *a, int *b)
{
/*
analyse:
遍历获取的随机函数数组;
if判断粗如;
*/
int i,j;
//数组b初始化
for(j = 0; j < M; j++)
b[j] = 0;
//数组a检索归纳
for(i = 0; i<N; i++)
{
if(a[i] > 100)
b[10]++;
else
b[a[i]/10]++;
}
/* ERROR:
int i;
for(i = 0; i<N; i++)
{
if(0 <=a[i] && a[i] <= 9)
b[1] = a[i];
else if(10 <=a[i] && a[i] <=19)
b[2] = a[i];
else if(20 <=a[i] && a[i] <= 29)
b[3] = a[i];
else if(30 <=a[i] && a[i] <= 39)
b[4] = a[i];
else if(40 <=a[i] && a[i] <= 49)
b[5] = a[i];
else if(50 <=a[i] && a[i] <= 59)
b[6] = a[i];
else if(60 <=a[i] && a[i] <= 69)
*b = a[i];
else if(70 <=a[i] && a[i] <= 79)
*b = a[i];
else if(80 <=a[i] && a[i] <= 89)
*b = a[i];
else if(90 <=a[i] && a[i] <= 99)
*b = a[i];
else if(a[i] >= 100)
*b =a[i];
}
*/
}
double rnd()
{
static int t=29,c=217,m=1024,r=0;
r=(r*t+c)%m;
return((double)r/m);
}
void main()
{
FILE *wf;
int age[N], i,d[M];
int b[N]={32,45,15,12,86,49,97,3,44,52,17,95,63};
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]); /*每行输出10个数*/
printf("\n\n");
fun(age,d);
for(i=0; i<10; i++)
printf("%4d---%4d :%4d\n", i*10, i*10+9,d[i]);
printf("Over 100 : %4d\n",d[10]);
/******************************/
wf=fopen("out.dat","w");
fun(b,d);
for(i=0; i<10; i++)
fprintf(wf,"%4d---%4d :%4d\n", i*10, i*10+9,d[i]);
fprintf(wf,"Over 100 : %4d",d[10]);
fclose(wf);
/*****************************/
}