数组查找元素

#include<stdio.h>
#include<stdlib.h>
void shuzhu1(int a[],int n)//找出数组中第一次出现只1次的数
{
	int i,c=0;
	for(i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			if(a[i]==a[j])
			{
				c++;
			}
		}
		if(c==1)
		{
			printf("%d",a[i]);
			break;
		}
		else
		{
			c=0;
		}
	}
}

void shuzhu2(int a[],int n)//找出出现最多次数的数
{
	int i,c=0;
	int count=0;
	int max;
	for(i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			if(a[i]==a[j])
			{
				count++;
			}
		}
		if(count>c)
		{
			c=count;
			count=0;
			//break;
			max=a[i];
		}
		else
		{
			count=0;

		}
	}
	printf("%d",max);
}
int main()
{
	int a[12]={2,8,6,5,4,2,1,86,5,8,8,1};
	shuzhu2(a,12);
}


posted @ 2017-09-04 17:54  小时候挺菜  阅读(242)  评论(0编辑  收藏  举报