数组查找元素

xiaoxiao2021-02-28  64

#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); }
转载请注明原文地址: https://www.6miu.com/read-76944.html

最新回复(0)