Answers for "write a program to print the occurrence of unique elements in an array"

0

write a program to print the occurrence of unique elements in an array

//write a program to print the occurrence of unique elements in an array
#include <stdio.h>

int main(int argc, char const *argv[])
{

    int arr[] = {4, 256, 2, 256, 4, 3, 3, 3, 5}, seen, count;
    int arr_length = sizeof(arr) / sizeof(int);

    for (int i = 0; i < arr_length; i++)
    {

        seen = 0;
        count = 1;
        for (int j = 0; j < i; j++)
        {
            if (arr[i] == arr[j])
            {
                seen = 1;
            }
            // printf("first loop\n");
        }
        if (seen == 0)
        {

            for (int k = i + 1; k < arr_length; k++)
            {
                if (arr[i] == arr[k])
                {
                    count++;
                    /* code */
                    // printf("condition\n");
                }
                // printf("second loop\n");
            }
            printf("%d occurs %d times\n", arr[i], count);
        }
    }
   

    return 0;
}
Posted by: Guest on July-12-2021

Code answers related to "write a program to print the occurrence of unique elements in an array"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language