Problem 43

2 comments on “Problem 43”


  • TADEPALLI

    #include
    int max(int arr[],int n)
    {
    int i,max=0;
    for(i=0;imax)
    max=arr[i];
    }
    return max;
    }
    int main()
    {
    int i,n,cnt[]={1,2,3,4,5};
    scanf(“%d”,&n);
    int arr[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
    for(i=0;i<5;i++)
    {
    int count=0,j;
    for(j=0;j<n;j++)
    {
    if(cnt[i]==arr[j])
    {
    count++;
    }
    }
    cnt[i]=count;
    }
    for(i=0;i<5;i++)
    printf("Type %d: %d bird\n",i+1,cnt[i]);
    int maxim=max(cnt,5);
    int cnnt=0;
    for(i=0;i<5;i++)
    {
    if(cnt[i]==maxim)
    cnnt++;
    if(cnnt==1)
    {
    printf("The highest frequency is %d\n",i+1);
    break;
    }
    }
    return 0;
    }


  • Nanditha

    #include
    int main()
    {
    int n,i,max,ans;
    scanf(“%d”,&n);
    int a[n],h[6]={0};
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    h[a[i]]++;
    }
    max=h[1];
    for(i=2;i<n;i++)
    {
    if(max<h[i])
    {
    max=h[i];
    ans=i;
    }
    }
    printf("%d",ans);
    return 0;

    }