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

来源:互联网 发布:东风(十堰)整合优化 编辑:程序博客网 时间:2024/04/25 18:55
#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 100void  statisticage(int people2[N],int count1[N]){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[N], int statistinum2[N]){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[N] ={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[N] =  {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[N] = { 0 };int statistinum[N] = { 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");}

0 0