您的位置:首页 > 其它

统计一个单位职工的年龄,要求把相同年龄最多的那个年龄找出来(可能有几个这样的年龄),并统计出现的次数

2014-05-16 23:54 477 查看
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>
#include<stdio.h>

#define N 100
void  statisticage(int people2
,int count1
)
{
for (int i = 0; i < N; i++)
{
if (people2[i] != 0)
{
count1[i]+=1;
}
for (int j = i + 1; j < N; j++)
{
if (people2[i]!=0 &&people2[i] == people2[j])
{
people2[j] = 0;
count1[i]+=1;
}

}
}

}

int  searchmaxtime( int count2
, int statistinum2
)
{
int max = 0,k=0;
for(int i = 0; i < N; i++)
{
if (max < count2[i])
{
max = count2[i];
}
}
for (int i = 0; i < N; i++)
{
if (max == count2[i])
{
statistinum2[k++] = i;
}
}
return k;
}
void main()
{
int people
=
{
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
39, 43, 23, 45, 65, 34, 63, 43, 43, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43,
49, 20, 20, 30, 23, 34, 42, 43, 12, 43
};
int people1
=  {
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
39, 43, 23, 30, 30, 34, 63, 43, 43, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 20, 30, 30, 34, 42, 43, 12, 43,
49, 20, 30, 30, 30, 34, 42, 43, 12, 43,
49, 20, 30, 30, 30, 34, 42, 43, 12, 43
};
int count
= { 0 };
int statistinum
= { 0 };
statisticage(people1, count);
int k=searchmaxtime( count, statistinum);
for (int i = 0; i < k; i++)
{
printf("最多人数的年龄=%d 人数=%d\n", people[statistinum[i]], count[statistinum[i]]);
}
system("pause");
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐