Solved programming problem

Finding the maximum frequency from 1D array in C.

Source code

#include<stdio.h>

int main()

{

    int array[100];

    int i,j,n,count=0,max=0,index=0;

    printf("Please Enter The array size: ");

    scanf("%d",&n);

    printf("
Please Enter %d elements of the array: 
",n);

    for(i=0; i<n; i++)

    {

        scanf("%d",&array[i]);

    }

    for(i=0; i<n; i++)

    {

        count=0;

        for(j=0; j<n; j++)

        {

            if(array[i]==array[j])  ///checking  if same element is available or not

            {

                count++;

            }

        }

        if(count>max) ///checking is it the maximum or not

        {

            max=count;

            index=i;

        }

    }

    printf("
The Max element is %d = %d times.
",array[index],max);

    return 0;

}

Output

Please Enter The array size:5

Please Enter 5 elements of the array:

1 3 1 1 2

The Max element is 1 = 3 times.

Join the discussion

Add your comment

3 previous comments

wherpathe

PMID 35642027 Free PMC article <a href=https://cialis.lat/discover-the-best-prices-for-cialis>online cialis</a> Dehydration should be corrected, but first the clinician should try to collect a urine sample to determine specific gravity

Loupesy

epivir hbv clindamycin and benzoyl peroxide topical gel side effects Celesio, active in both drugs wholesale and retail, has spedup the expansion of its network of pharmacies in continentalEurope under the Lloyds brand, and aims to significantlyincrease its earnings next year, Helmes also said <a href=https://buylasixon.com/>lasix dosage for dogs</a> If a couple of lymph nodes are positive, then you have a few options

CessyCary

Afynmz The frictional force is horizontal to the left in Figure a and to the right in Figure b. [url=https://bestadalafil.com/]Cialis[/url] Elevated fasting serum insulin level. <a href="https://bestadalafil.com/">cialis prescription</a> Rmptrb Kauotx Acheter Cialis Generique En Ligne https://bestadalafil.com/ - cialis 5 mg best price usa